Note this is run on a debian linux environment
I have the following sample script called HelloWorld.sh
#!/bin/bash echo "Hello World" exit 1
I then run the following command
script -c ./HelloWorld.sh foo ; echo $?
$? returns 0 which is expected since the script command itself ran successfully. However, I want the return code HelloWorld.sh which would be 1 if I just ran the following command.
bash HelloWorld.sh ; echo $?
Looking at the man page, I see that the script command doesn't return anything so the following wouldn't help either
return_code=`script -c ./HelloWorld.sh foo`
The question I would like to ask is whether there is a way that I can get the return value of HelloWorld.sh when running it in the context of the script command such as sending the exit value to the parent shell. If not, how would you recommend doing it?
My possible answers on how I would do it if I can't use the script command
- Have HelloWorld.sh write to shared memory using the shm API
- Have HelloWorld.sh write to a file
Both methods require cleanup of the shared memory object and the file respectively, so I am asking for my own personal knowledge whether there is a simpler solution