> [EMAIL PROTECTED] 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 > [EMAIL PROTECTED] > http://sudrala.de >
Thanks for the reply! While you are correct, this isn't exactly the intended functionality. In the end I'd like $chkFile variable to contain the path or exit the script printing the error message. This is probably unclear due to the fact that only a snippet is posted and not the entire script.