Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-10-2011, 02:28 AM   #1
LQ Newbie
Registered: Oct 2009
Posts: 27

Rep: Reputation: 0
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
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-10-2011, 07:29 AM   #2
Registered: May 2001
Posts: 29,280
Blog Entries: 55

Rep: Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515Reputation: 3515
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:"; }
Old 09-10-2011, 09:41 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
3 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] store the return value of $DISPLAY into my perl script casualzone Linux - Software 3 07-22-2011 12:48 AM
Using ping's return in a shell script brgsousa Linux - Software 3 05-28-2008 02:19 PM
Return value to shell in script mwade Linux - Newbie 11 08-18-2006 09:49 AM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM
return key on shell script chupacabra Programming 2 10-22-2002 12:11 PM

All times are GMT -5. The time now is 10:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration