0

I have the following bash code which I want to run within a perl script. As a bash script the code runs without any error. But in the perl script it gives the error: Bad name after bash' at ./061_rewrite_aws.pl line 48.

system(' 'bash' '-c' <<'END_SHELL_CODE';
AWS_Base="/run/user/1000/gvfs/smb-share:server=192.168.0.205,share=zmd-backup"
 pushd /home/zmd/AWS/AWS_DataDirs
 cp -R $AWS_Base/* ./
popd
'END_SHELL_CODE' ');

Assistance will be appreciated

1
  • You're trying to run this bash script with perl right? bash AWS_Base="/run/user/1000/gvfs/smb-share:server=192.168.0.205,share=zmd-backup"; pushd /home/zmd/AWS/AWS_DataDirs cp -R $AWS_Base/* ./; popd; Commented May 1, 2020 at 17:25

1 Answer 1

2

I think there's just some quoting errors with that line of perl.

  1. system takes a list of strings as arguments, so I changed that quoting to be a list of strings.
    • Right now I think perl is parsing that line and expecting bash to be the name of some variable.
  2. The here-doc formatting was off. I think the ; after END_SHELL_CODE on the first line, and having END_SHELL_CODE in single quotes at the end didn't work with perl's formatting, so I removed that.

Something like this worked for me:

system('bash', '-c', <<'END_SHELL_CODE'
AWS_Base="/run/user/1000/gvfs/smb-share:server=192.168.0.205,share=zmd-backup"
pushd /home/zmd/AWS/AWS_DataDirs
cp -R $AWS_Base/* ./
popd
END_SHELL_CODE
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much @GandhiGandhi, the code as per your modification works perfect. Thanks for your time and effort.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.