0

I'm seeing this error from my tcsh script and I can't figure out why.

Script:

#!/usr/bin/env tcsh
foreach n (0 1)
  set PERL_CMD = "perl -e 'print qq^RUNNING^; exit ${n} '"
  echo "PERL_CMD:\n${PERL_CMD}"
  ${PERL_CMD}
  echo
end

Result:

[]$ ./test_perl_e.csh
PERL_CMD:
perl -e 'print qq^RUNNING^; exit 0 '
Can't find string terminator "'" anywhere before EOF at -e line 1.

PERL_CMD:
perl -e 'print qq^RUNNING^; exit 1 '
Can't find string terminator "'" anywhere before EOF at -e line 1.

Running either of those PERL_CMD on the command line works fine:

[]$ perl -e 'print qq^RUNNING^; exit 1 '
RUNNING[]$ 

When I embed into a tcsh script, it echo's back fine. However when I try to run it, it's broken.

I've tried a bunch of variations, but I'm stumped. What did I do wrong?


Using perl/5.24

[]$ perl -v
This is perl 5, version 24, subversion 0 (v5.24.0) built for x86_64-linux
ercousin
  • 3
  • 2

1 Answers1

2

The idiomatic way to do in cshell, what you are trying to do , is to a) use arrays and b) employ proper quoting operators. You can read up on them in man tcsh.

#!/usr/bin/env tcsh
set perl = "perl"

set options = ( -w -l )

foreach n (0 9)
  set cmd = "\
    print qq/running/;\
    exit($n); \
  "

  "${perl}" \
    ${options[*]:x} \
    -e ${cmd:q}  \
  ;

  echo ""
end 
guest_7
  • 5,698
  • 1
  • 6
  • 13