[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell kung-fu with set -e, return codes and i/o redirection in while read ... loop



In <[🔎] 20090719114552.GA15085@resivo.wgnet.de>, Jonas Meurer wrote:
>so second thought was to use return codes inside the while loop and
>check for them after the while loop. but that failed due to 'set -e'
>being set. therefore any return code != 0 caused the script to stop
>immediately instead of just exiting the while loop.

If you use the command in an if/while/until statement, it can fail without 
terminating the script, even when the "-e" shell option is set.  You might 
be able to use something like:

while something; do
	if cmd_that_can_fail; then :; else
		# Just can check $? if you want
		# to know the exact return code.

		# Print a warning, but
		continue
	fi
done

>only one issue remains that still doesn't work as expected:
>if handle_crypttab_line_start fails with a warning, it still returns 0
>(success) as return code.

That "warning" seems more like an "error" to me -- the function fails.

>unfortunately I don't see an option t change
>that one.
>in initscripts it would be fatal for handle_crypttab_line_start to exit
>with any return code != 0 as that would cause the whole initscript to
>stop instead of processing the remaining crypt targets.

Using something like the above you should be able to try to mount the all 
entries, print a warning for each one that fails, and then return an 
appropriate code to indicate success/partial success/failure.

\-- 
Boyd Stephen Smith Jr.           	 ,= ,-_-. =.
bss@iguanasuicide.net            	((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy 	 `-'(. .)`-'
http://iguanasuicide.net/        	     \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: