asked by Katherine Wall in Technology near Delhi 'O' Delhi, Erskineville Road, Newtown NSW, Australia on 28 May,2018
asked by Katherine Wall in Career near Des Renford Leisure Centre, Jersey Road, Maroubra NSW, Australia on 28 May,2018
#!/bin/bash
set -e
function foo() {
# commands that might fails and I want to exit my script
...
echo "result I need as output"
}
my_var=$(foo)
echo "I don't want this if there is an error inside foo"
Using set -e
(in bash 4.4.19
) does not seem to work with subshells i.e. the last echo
command is still being executed). How can I write the code to make the script exit if any of the commands inside foo
terminate with non-zero exit code.
Choose a test user to login and take a site tour.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.