bobdis has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks!

I would like to take a value from a unix shell script, pass it to a perl script where I can manipulate the value, then pass the results back to the unix shell script. I appreciate any help.

Thank you,
Bob

  • Comment on Passing values between shell and Perl scripts

Replies are listed 'Best First'.
Re: Passing Values
by Aristotle (Chancellor) on Sep 06, 2002 at 15:17 UTC
    @ARGV is your ticket. As for returning results to the script, you can either capture the Perl script's STDOUT or use exit to signal success/failure.

    Makeshifts last the longest.

Re: Passing Values
by krujos (Curate) on Sep 06, 2002 at 15:33 UTC
    One way to do this is to call the perl script with the variable as an argument. You can then use @ARGV to get the variable and mess with it. To get it back out you can set an env variable and manipulate it in the shell script again.
    Good Luck.
    Josh
Re: Passing Values
by flounder99 (Friar) on Sep 06, 2002 at 15:53 UTC
    temp.pl ---------------------- #! /usr/bin/perl print $ARGV[0] + 1; temp.sh ---------------------- #! /usr/bin/bash MYVALUE=1; NEWVALUE=`./temp.pl $MYVALUE` echo $NEWVALUE execution ---------------------- $./temp.sh 2

    --

    flounder

Re: Passing Values
by zentara (Cardinal) on Sep 06, 2002 at 16:01 UTC
    If you mean doing this with both scripts running simultaneously,
    you might want to look at pipes. You can make a pipe to go from
    the shell script to the perl script, another pipe to return the values
    from the perl script to the shell script.
    You treat the pipes as filehandles to read and write too.
    In bash you can make the pipes with the mkfifo command,
    then call the perl script with system. The perl script should
    use the pipes as it's stdin and stdout.
    It's an alternative to running the perl script and capturing it's
    output. Read  "perldoc -q  pipe".