[英]Perl scripting in Linux bash scripting
我正在閱讀bash腳本之一,遇到以下幾行。 我無法猜測以下幾行到底在做什么? 任何人都可以給我一些暗示,這些行到底在做什么。 我已經分別執行了這些行,但是沒有輸出。 我什至嘗試使用斷點。
ssh $HOST bash -e <<
'END' 2>&1 |
/usr/bin/perl -ne
'BEGIN { $|=1 } ;
if (/(bmake|create_dirs\.sh)\[\d+\] Leaving/)
{ --$indent };
print " "x($indent * 4), "$_" ;
if (/(bmake|create_dirs\.sh)\[\d+\] Entering/) { ++$indent }'
我期待任何回應。
謝謝
它是用於跟蹤標識的腳本。 在“離開”行上,縮進減少,在“進入”行上,縮進增加。 然后,我們根據縮進變量看到空格被打印出來了。 詳細:
/usr/bin/perl -ne
-n
標志在腳本周圍放置while(<>)
循環,這基本上使perl從stdin或參數文件中讀取。
BEGIN { $|=1 }
自動沖洗功能已打開。
if (/(bmake|create_dirs\.sh)\[\d+\] Leaving/) { --$indent };
此正則表達式在這里查找諸如
bmake[9] Leaving
create_dirs.sh[2] Leaving
找到后, $indent
變量減少1。
print " "x($indent * 4), "$_" ;
這將打印一個空格,重復4 * $indent
次,然后輸入行。
if (/(bmake|create_dirs\.sh)\[\d+\] Entering/) { ++$indent }
該行通過與上述相同的方法增加縮進量。
有關正則表達式的更多說明(盡管我從此站點清除了語法,請參見此處 ):
NODE EXPLANATION
--------------------------------------------------------------------------------
( group and capture to $1:
--------------------------------------------------------------------------------
bmake literal string 'bmake'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
create_dirs\.sh literal string 'create_dirs.sh'
--------------------------------------------------------------------------------
) end of $1
--------------------------------------------------------------------------------
\[ literal string '['
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\] Leaving literal string '] Leaving'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.