user1121951
user1121951

Reputation:

Perl's %ENV doesn't works in one-liner

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?

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

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

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 )

/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

Upvotes: 1

Views: 153

Answers (1)

arco444
arco444

Reputation: 22841

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'

Upvotes: 2

Related Questions