繁体   English   中英

Linux bash脚本中的Perl脚本

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM