LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 07-07-2008, 06:14 PM   #1
guttersnipe
LQ Newbie
 
Registered: Jun 2007
Distribution: Gentoo, Ubuntu
Posts: 23

Rep: Reputation: 0
exit codes history


How do I access the history of the $? variable?

I know that $? returns the exit codes of the LAST executed program in your session, but is there a way to access the history of this variable such as during a pipelined set of commands in BASH and/or PERL? This would be especially useful when piping the output of your command through a grep, then testing the exit status of the original command--not grep's exit status.

I ran into this problem while writing a perl script that incorporates an rsync command.

Code:
system( "rsync -Kcpogltr --log-format=%n%L /from/dir/ /to/dir/ | grep -v /$" );
The above code will rsync the files from /from/dir/ to the files in /to/dir/. The --log-format=$n%L combined with the | grep -v /$ will print to the user all the files that have been synced (the grep bit hides the FOLDERS that normally get printed). After this call is made, I want to check the status of rsync and preform necessary error-checking, but I can't find a way around checking grep's status.

I understand that--programmatically with perl and/or bash--there is surely a way around this without the pipe, but I still want to know if there is a way to glimpse into the history of exit statues with the $? variable outside of this particular situation.


Thanks in advance!
 
Old 07-07-2008, 08:35 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
There is no history of exit status codes.

Bash has a array of exit status codes for a pipeline. See PIPESTATUS in man bash. Otherwise, the exit status is the status of the last command of the pipeline.
 
  


Reply

Tags
bash, codes, environment, exit, grep, perl, rsync, shell, variables


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
'make' exit codes jhwilliams Programming 1 08-20-2007 12:22 PM
dhcpcd in Slackware 11.0 does not return any exit codes other than 0? Ken-ji Slackware 1 04-01-2007 07:55 PM
Bash scripting problem with exit codes Jeiku Programming 2 05-15-2006 02:22 AM
Are the hex codes for colors in a jpg the same codes as used in html? abefroman Linux - Security 3 07-31-2005 04:21 PM
exit codes introuble Programming 2 05-08-2005 01:53 PM


All times are GMT -5. The time now is 05:59 PM.

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