我怎样才能传给我的Bash循环变量间的Perl preTER? [英] How can I pass on my Bash loop variable to the Perl interpreter?

查看:156
本文介绍了我怎样才能传给我的Bash循环变量间的Perl preTER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在bash和Perl的组合来修改某些脚本。麻烦的是,Perl的认为 $指数是其自己的变量,这是从来没有定义的:

I'm trying to modify some scripts with a combination of Bash and Perl. The trouble is that Perl thinks that $index is its own variable, which is never defined:

for index in {1..25}; do
    perl -pi -e 's/\d+/$index/' cmd_$index.sh;
done

有没有一种方法,使 $指数 Perl的单行内穿的斗篷猛砸?

Is there a way to make $index wear its Bash cloak within the Perl one-liner?

推荐答案

挤压的出口指数; 不要循环。请参阅 $ ENV {指数} 在Perl程序的主体

Squeeze an export index; in the do loop. Refer to $ENV{index} in the body of the Perl program.

另外:使用双引号... $指数...来shell变量插值到前pression,构成了Perl程序的主体。如果你想扩展这一行,注意正确的逃生Perl的前pressions,如 $ 的变量名,也许反斜杠,这样是除$ p $被Perl PTED,而不是shell。

Alternatively: Use the double quotes "… $index … " to interpolate the shell variable into the expression that makes up the body of the Perl program. In case you want to expand this one-liner, take care to properly escape Perl expressions, such as $ on variable names, and perhaps backslashes, so that are interpreted by Perl, not the shell.

这篇关于我怎样才能传给我的Bash循环变量间的Perl preTER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆