我正在阅读其中一个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 }'我期待着任何善意的回复。
谢谢
发布于 2013-02-20 20:53:08
在“离开”行,缩进量减少,在“进入”行,缩进量增加。详细说明:
/usr/bin/perl -neperl标志在脚本周围放置了一个while(<>)循环,这基本上使-n从标准输入或参数文件中读取。
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 }此行以与上面相同的方法增加缩进。
更多关于正则表达式的解释(参见here,不过我从这个站点上清理了语法):
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'https://stackoverflow.com/questions/14980132
复制相似问题