Return Code to shell script

Hi, I need to send the return code from a script to the parent shell script.
But i am suppressing outputs while calling the child script.
Is there any way still to get the return code from the child script with suppress output.

Below is my script:
I am using :blush: while calling return.sh because i want to suppress the output.But everytime its returning a 0(zero) as a success status. But i want 123(thats in the return.sh).Below is the script for parent & child script.

:$(./return.sh)
echo reply is "$?"

return.sh

exit 123

If you don(t want the output of return.sh
no need of :

 : [...]
             The null command.  Exit status is set to zero.

you can try this way

./return.sh >/dev/null;echo reply is $? 
1 Like

Your 'NOP' : is just that a 'NOP' with a meaningless argument of $(./return.sh) so its RC will always be zero, '0'.

[Prompt]./return.sh 2>&1 > /dev/null
[Prompt]echo "$?"

This will suppress most stuff printed to the terminal window but allow the RC to pass through.

1 Like

Thanks all for replying.

I have to use :$(can't use any other code for suppress output).
Is there a way to get return code while using :blush:

NO!

As you have been told by ctac_ and by wisecracker, the exit code from the : command is zero. Always zero. No matter what comes on the line after the leading : , the exit code from that command line will be zero.

And, NO! you do not have to use the : command to suppress output from a command substitution. And, with what you have shown us there is no reason to use command substitution at all.

If we knew what you were trying to do (instead of how you think you need to do it), we might be able to make suggestions that would meet your needs. The suggestions ctac_ and wisecracker supplied seem to meet your requirements as they have been stated:

  1. run your script named return.sh ,
  2. discard any output sent to standard output by return.sh , and
  3. print the exit code returned by return.sh .

Although the code suggested by ctac_ more correctly represents the output that would be produced by the : command with a command substitution that failed. The : command redirects output directed to standard output by a command substitution to /dev/null , but it does not discard output directed to standard error output by a command substitution like the code suggested by wisecracker does.

1 Like

I will add to Don's reply how are you going to catch a strange error that completely exits your result.sh .
The code below will NEVER reach your exit 167 ...
For example try this, I have called it RC.sh:

#!/bin/sh
# RC.sh
echo 'test'
echo 'bad line"
exit 167

OSX 10.13.3, default bash terminal...

Last login: Tue Mar 13 12:18:13 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./RC.sh 2>&1 > /dev/null
./RC.sh: line 4: unexpected EOF while looking for matching `''
./RC.sh: line 6: syntax error: unexpected end of file
AMIGA:amiga~/Desktop/Code/Shell> echo "$?"
2
AMIGA:amiga~/Desktop/Code/Shell> _