Zilore Mumba
Zilore Mumba

Reputation: 1570

How to run run bash code in a perl script

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

Upvotes: 0

Views: 60

Answers (1)

GandhiGandhi
GandhiGandhi

Reputation: 1350

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
);

Upvotes: 2

Related Questions