Sample Header Ad - 728x90

Why does exiting with a stored returncode of a nested command result in different returncodes in Dash and Bash?

9 votes
1 answer
551 views
Running bash -c 'bash -c "echo test1; exit 1;" &> /tmp/x; buildresult=$?; tail -n 100 /tmp/x; exit $buildresult;' results in test1 being printed to console and echo $? to print 1 which in my understanding is correct, because the command should return with what the inner [b/d]ash -c returned whereas dash -c 'dash -c "echo test1; exit 1;" &> /tmp/x; buildresult=$?; tail -n 100 /tmp/x; exit $buildresult;' results in the same output, but returns with 0 according to echo $?. I'd like to understand this difference in order to broaden my understanding of shells and portable shell programming. I'm using bash 4.4.12 and dash 0.5.8-2.3ubuntu1 on Ubuntu 17.10 (Artful Aardvark).
Asked by Kalle Richter (2252 rep)
Nov 18, 2017, 07:04 PM
Last activity: Oct 18, 2023, 08:03 PM