Perl的%ENV不适用于单行

时间:2022-12-27 22:12:58

I write simple bash line that should replace the LOGIN word in some bash script (will replace the word LOGIN to admin word) But it doesn’t work?

我写了一些简单的bash行,它应该替换一些bash脚本中的LOGIN字(将LOGIN替换为admin字)但它不起作用?

But when I type bash command on my Linux/solaris machine and then run separately the commands then its work

但是当我在我的Linux / solaris机器上键入bash命令然后单独运行命令然后它的工作

so why the bash one liner not work ( what’s the diff here ? )

那么为什么bash one liner不起作用(这里的差异是什么?)

bash one liner line

打一条班轮线

/tmp ROOT > bash -c 'export LOGIN=admin  ; /usr/local/bin/perl -i -pe 's/LOGIN/$ENV{LOGIN}/' /tmp/pass_login.bash'
ENV: Undefined variable.

run command separately under bash shell ( works fine )

在bash shell下单独运行命令(工作正常)

/tmp ROOT >  bash
bash-3.2#    export LOGIN=admin
bash-3.2#    /usr/local/bin/perl -i -pe 's/LOGIN/$ENV{LOGIN}/' /tmp/pass_login.bash

.

my script

 more pass_login.bash


 #!/bin/bash

 MY_LOG_NAME=LOGIN

1 个解决方案

#1


1  

Doesn't look to me like you have your quotes/variables escaped properly. Try this instead:

我不认为你的报价/变量正确转义。试试这个:

bash -c 'export LOGIN=admin  ; /usr/local/bin/perl -i -pe "s/LOGIN/\$ENV{LOGIN}/" /tmp/pass_login.bash'

#1


1  

Doesn't look to me like you have your quotes/variables escaped properly. Try this instead:

我不认为你的报价/变量正确转义。试试这个:

bash -c 'export LOGIN=admin  ; /usr/local/bin/perl -i -pe "s/LOGIN/\$ENV{LOGIN}/" /tmp/pass_login.bash'