BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

If I use systask to run two linux commands on one line, e.g.:

systask command "gzip ~/notthere.txt; touch ~/foo.txt" status=mystatus shell wait;
%put >>&mystatus<< ;

The status returned is the status of the second command (touch in this case).  So even if the first command (gzip) fails, my status will be set to 0 because the second (touch) succeeded.  I recognize it's linux setting the exit code, not SAS. 

 

Is there an easy way to grab the maximum status from all the commands that were submitted?

 

Okay, I googled, looks like using the && operator could work for what I want.  If the first command fails, the second command won't be executed and I'll get the exit code from the first command:

systask command 'gzip ~/notthere.txt && touch ~/foo.txt' status=mystatus shell wait;
%put >>&mystatus<< ;

Is there a better way?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

&& is the UNIX way to do this; you'll see it in all kinds of setup/installation and other shell scripts.

You can, of course, always catch the exit codes separately:

filename os pipe 'gzip ~/notthere.txt; RC1=$?; touch ~/foo.txt; RC2=$?; echo "rc1=$RC1 rc2=$RC2"';

data retcode;
infile os end=done;
length retcodes $20;
input;
if done;
retcodes = _infile_;
run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

&& is the UNIX way to do this; you'll see it in all kinds of setup/installation and other shell scripts.

You can, of course, always catch the exit codes separately:

filename os pipe 'gzip ~/notthere.txt; RC1=$?; touch ~/foo.txt; RC2=$?; echo "rc1=$RC1 rc2=$RC2"';

data retcode;
infile os end=done;
length retcodes $20;
input;
if done;
retcodes = _infile_;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1065 views
  • 1 like
  • 2 in conversation