0

Severe newb here. I have a shell script that simply calls a perl script to create a file. It works if I double-click the SH file, but fails if I call the file in a terminal. here is the entire SH file:

#! /bin/bash
# Run Will's JSON Script


perl /Users/j.douet/Documents/JSON/pbmJson.pl -i /Jaspersoft/tmp/output/hospicemed/hhcsys/hhcsys_hospicemed_201711251121140465.txt -m newPatient -n 1234 > /Jaspersoft/tmp/output/hospicemed/hhcsys/hhcsys_hospicemed_201711251121140465.json;

It really is that simple. No arguments yet as I am testing. When I double-click, my output file is created, but when I execute

sh runhmJSON.sh

I get errors within the perl script, all similar to:

/Users/j.douet/Documents/JSON/pbmJson.pl: line 3: use: command not found

Thoughts?

  • What happens if you run perl /Users/j.douet/Documents/JSO... (the whole line from the script) directly in Terminal? Are you sure it works on double-click or does it just not show any errors? – nohillside Nov 27 '17 at 17:42
1

That error indicates your pbmJson.pl is being run by a shell, and not by perl:

$ cat someperlcode
printf "hi\n";
printf "there\n";
use strict;
$ perl someperlcode
hi
there
$ sh someperlcode
hi
there
someperlcode: use: not found
$ use
mksh: use: not found
$ bash
bash-3.2$ use
bash: use: command not found
bash-3.2$ exit
exit
$ 

As written, I see no error in what you've posted:

$ cat code
#! /bin/bash

perl someperlcode > output
$ chmod +x code
$ rm output
$ ./code
$ cat output
hi
there
$ rm output
$ sh code
$ cat output
hi
there
$ 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .