LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 09-10-2011, 03:28 AM   #1
csegau
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:

shell.sh contains

read Latest_file <<< $( perl.pl arg1 )
-----------------------------------------

perl.pl 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, 08:29 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,685
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Something like
Code:
Latest_file=$(perl.pl arg1)
but using all-caps variable names
Code:
VARIABLE=$(perl.pl arg1 2>/dev/null)
makes things easier to read and recognize.

Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/ 
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq 
http://wooledge.org/mywiki/BashPitfalls"; }
 
Old 09-10-2011, 10:41 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
  


Reply


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 01:48 AM
Using ping's return in a shell script brgsousa Linux - Software 3 05-28-2008 03:19 PM
Return value to shell in script mwade Linux - Newbie 11 08-18-2006 10:49 AM
return value from shell script to c code? khucinx Programming 1 05-13-2004 04:43 PM
return key on shell script chupacabra Programming 2 10-22-2002 01:11 PM


All times are GMT -5. The time now is 07:40 AM.

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