-   Programming (
-   -   return value from perl to shell script (

csegau 09-10-2011 03:28 AM

return value from perl to shell script
Hi All,

i have a shell script which in turns calls a perl script.
this perl script return the file name, which i want in my calling shell script. How can i get the return value in my shell scipt.

ex: contains

read Latest_file <<< $( arg1 )
----------------------------------------- returns the latest file with extension arg1

therefore in my perl script i use

my @list = `ls *.arg1`;
#then do some processing
#finally i return the latest file as
print $latest_file;


thanks in advance :)

unSpawn 09-10-2011 08:29 AM

Something like

Latest_file=$( arg1)
but using all-caps variable names

VARIABLE=$( arg1 2>/dev/null)
makes things easier to read and recognize.


function help() { echo "Bash scripting guides:"; }

theNbomr 09-10-2011 10:41 AM

I would like to point out the distinction between the meaning of 'return' and, in this case, 'write to stdout'. A return value is the integer value returned by the application (exit code), and if the calling process is bash or most other shells, is automatically assigned to the shell variable '$?'. Conventionally, the value '0' (zero) means 'success', whatever that might imply with respect to the particular program. Non-zero values are conventionally used to indicate some form of failure. This is conceptually distinct from output written to either of the standard output streams, stdout and stderr.
The data written to stdout may be redirected to some other stream or file descriptor, or in the case of bash, may be used in command substitution, which seems to be the case here. Assigning to a bash variable using command substitution is common idiom in bash shell scripting, and that seems to be the concept that addresses the OP's question. The subject of command substitution is well addressed in several of unSpawn's links.

--- rod.

All times are GMT -5. The time now is 11:33 AM.