|
From: | Bernd Eggink |
Subject: | Re: Exit application with two function calls |
Date: | Sun, 27 Jan 2008 17:19:45 +0100 |
User-agent: | Thunderbird 2.0.0.9 (X11/20071031) |
abi@e-arroyo.net schrieb:
Hi, I am working on a script and ran into an unusual program. Consider the following script which I called how.sh. ===== #!/bin/bash error () { echo -e "\n\terror: ${*}\n" exit; # kill $$ } check_file () { input="$*" if [ -e $input ]; then echo "$input" else error "invalid directory: $input" fi } chkFile="`check_file $1`" echo $chkFile echo "don't print" ===== When I run the command above I get this output: # ./how.sh /asdf error: invalid directory: /asdf don't print
The reason is that `check_file` is executed in a subshell, so 'exit' just leaves the subshell, not the script itself.
The command substitution is unnecessary anyway, as the result (if any) will simply be $1 itself. Thus, if you replace the main part by
check_file $1 echo $1 it should work as expected. Regards, Bernd -- Bernd Eggink monoped@sudrala.de http://sudrala.de
[Prev in Thread] | Current Thread | [Next in Thread] |