[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



Hello,

On 19/07/2009 Chow Loong Jin wrote:
> On Sunday 19,July,2009 07:45 PM, Jonas Meurer wrote:
> > so the script needs to be changed to exit the while loop with
> > information about whether
> >  - the target was found in crypttab
> You already have that information. In the snippet of code:
> 
> found="no"
> egrep -v "^[[:space:]]*(#|$)" "$TABFILE" | while read dst src key opts; do
>     if [ "$1" = "$dst" ]; then
>         found="yes"
>         handle_crypttab_line_start "$dst" "$src" "$key" "$opts" <&3
>         exit 0
>     fi
> done 3<&1
> 
> Note the value of the variable "found". If it's "yes", it was found,
> otherwise it's not.

no, unfortunately not. the while read ... loop opens a subshell, thus
the found="yes" inside is pointless.

greetings,
 jonas


Reply to: