in reply to Re^2: pass perl variable to shell script
in thread pass perl variable to shell script

The command substuition captures the output of the perl-script at the shell-side.

So if you only have to pass one value you simply print it to standard output in Perl.

#in perl-script "script.pl" print $variable; #in the shell-script: variable=$(perl script.pl) echo $variable
If you must pass more than one variable you e.g. print them in a certain format "$var1=$var2=$var3" and parse that on the shell side.

Replies are listed 'Best First'.
Re^4: pass perl variable to shell script
by arthurs (Novice) on Aug 11, 2010 at 17:01 UTC
    morgon, I only have one script -- shell script, in which i have a block of perl code. Lets forget I have 'print' statement in the perl block. Lets say I am setting str3 somewhere in the middle of the perl block. After perl block has finished executing, I am back in the shell part of the code and need to get the content of str3 variable that was set in the perl block of the code. How do I do it?
      How do I do it?

      Programs communicate via STDIN/STDOUT, so the way morgon and others showed you is the way to do it

        OK, so you are saying that in order for me to get access to a variable that was set in perl block, I woud need to print that variable either to stdout or to a file and then read it back in the shell part of the code? Since I don't want to print into a file, then I need to print to stdout. But when morgon says:
        variable=$(perl script.pl)
        what is 'script.pl'? I don't have a .pl script. I only have .sh script.
      Without changing the perl code to report the value somehow, there is no way.