[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

On 19/07/2009 Boyd Stephen Smith Jr. wrote:
> 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

ah, that indeed is an option. I now solved the issue the following way:

- in cryptdisks_{start|stop} only one device is setup anyway. here I
  simply don't use set -e and check for the error code instead.

- in cryptdisks initscript set -e is set, and handle_crypttab_line_start
  is wrapped in an if statement:

  handle_crypttab_line_start "$dst" "$src" "$key" "$opts" <&3 || true


Attachment: signature.asc
Description: Digital signature

Reply to: