Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: perl callable from bash?

by targetsmart (Curate)
on Apr 13, 2009 at 13:45 UTC ( #757209=note: print w/replies, xml ) Need Help??

in reply to perl callable from bash?

Which I at first thought had to do with not getting the variable right--- but a little detective work convinced me that what it couldn't find were the two scripts.
IMO you are wrong, if you don't have script in place, the shell script will say
./ line 3: firstscript: command not found ./ line 4: secondscript: command not found
IMO you have problem with arguments only, and might be some problems with the absolute path of the first and second script(as other monks mentioned).
generally if you are dealing with filenames in shell scripts, just check it existence before using it for further processing.
you can use something like
-e file True if file exists. -f file True if file exists and is a regular file. -r file True if file exists and is readable. -s file True if file exists and has a size greater than zero. -O file True if file exists and is owned by the effective user i +d. -G file True if file exists and is owned by the effective group +id.
and more of this can be seen in your shell manual(the above operators are from bash manual), use those effectively to figure out whether the file exists and continue only in such case. For the script use
-x file True if file exists and is executable.
before calling it from your shell script.

if I write your script (shown in OP), in bash, it will be like

#!/bin/bash echo -e "received arguments >$*<" filename=$1; script1='fristscript'; # use absolute path script2='firstscript'; # use absolute path if [ -f $filename ] ; then echo -e "executing scripts $script1, $script2"; if [ -x $script1 ]; then echo -e "executing $script1..." $script1 $filename else echo -e "$script1 not found"; fi if [ -x $script2 ]; then echo -e "executing $script2..." $script2 $filename else echo -e "$script2 not found"; fi else echo -e "$filename is not readable or doesn't exist"; fi
Hope this helps.
(again the above bash code can be written even more effectively, but that is not the point of discussion)

-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://757209]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-01-28 06:44 GMT
Find Nodes?
    Voting Booth?