1

I have a bash script (script A) which runs a secondary bash script (script B).

sh scriptB.sh
exitStatus = ?

I need to get the exit code of the script B when I run it inside script A.

How can I do?

5
  • $? test this value. It contains the exit status of the previous command. Commented Jun 21, 2015 at 12:02
  • ah ok thanks I thought it wouldn't work inside a script :/ so silly Commented Jun 21, 2015 at 12:06
  • Should I post it as an answer ? What's the proper custom to do at SO ? (I am new here =] ) Commented Jun 21, 2015 at 12:08
  • ^^ Yes, please post that as answer... Commented Jun 21, 2015 at 12:32
  • You also cannot have spaces on each side of the equal sign with variable assignments in bash. It should be: exitStatus="$?" Commented Jun 21, 2015 at 12:35

1 Answer 1

1

See 3.4.2 Special Parameters of the Bash Reference Manual.

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.

?

($?) Expands to the exit status of the most recently executedforeground pipeline.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.