Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/egrunner: inject set -e in subcommands and command substitutions #83

Open
myitcv opened this issue Oct 25, 2018 · 0 comments
Open

Comments

@myitcv
Copy link
Owner

myitcv commented Oct 25, 2018

To ensure any failures bubble up to the top-level script.

Also, for process substitutions:

cat <(echo "hello"; false; echo "nothing") <(echo "goodbye"; false; echo "really")

will need to be rewritten to something like:

pushd $(mktemp -d) > /dev/null
mkfifo f1
(set -eu; set -o pipefail; echo "hello"; $comm; echo "nothing") > f1 2>&1 &
echo $! >> pids
mkfifo f2
(set -eu; set -o pipefail; echo "goodbye"; $comm; echo "really") > f2 2>&1 &
echo $! >> pids
cat f1 f2
for pid in $(<pids)
do
	wait $pid || echo $pid >> failed
done
if [ -e failed ]
then
	echo "command failed"
  	rm -rf $PWD
  	popd > /dev/null
  	false
else
	rm -rf $PWD
	popd > /dev/null
fi

which gives:

$ pushd $(mktemp -d) >/dev/null
$ mkfifo f1
$ (
        set -eu
        set -o pipefail
        echo "hello"
        false
        echo "nothing"
) >f1 2>&1 &
$ echo $! >>pids
$ mkfifo f2
$ (
        set -eu
        set -o pipefail
        echo "goodbye"
        false
        echo "really"
) >f2 2>&1 &
$ echo $! >>pids
$ cat f1 f2
hello
goodbye
$ for pid in $(<pids); do
        wait $pid || echo $pid >>failed
done
$ if [ -e failed ]; then
        echo "command failed"
        rm -rf $PWD
        popd >/dev/null
        false
else
        rm -rf $PWD
        popd >/dev/null
fi
command failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant