Stef Bon wrote:
> Hello,
> 

>         elif [ $(echo "$MOUNT_option" | grep "AUTOFS_USER" | wc --chars) 
> -gt 0 ]; then
> 
> 
>             AUTOFS_USER="$(echo $MOUNT_option | cut --delimiter='=' 
> --fields=2 --only-delimited)"

with sed:

if echo ",$MOUNT_options" | grep ",AUTOFS_USER";then
        AUTOFS_USER="$(echo ,$MOUNT_options | sed 
's%.*,AUTOFS_USER=%%g;s%,.*%%')"
fi

what above commands do: the whole block creates a variable only
when AUTOFS_USER is an option. and only when there actually is
"=" and anything after it, the variable is non-empty. the if
works also with ordinary commands, no [] needed. the sed does
extract the last AUTOFS_USER option's parameter. in the sed
command, the first command does erase all ",AUTOFS_USER="
and anything before them. the ";" is a command-seperator in
sed, and the next command is performed after the first has
finished. the second sed-command does erase "," and everything
after it. there is a "," at the beginning of the echo-input,
and so everything is erased by this second command, unless the
first one did actually erase the ",AUTOFS_USER=" thereby leaving
the stuff after the "=" untouched. i.e. the first command clips
the beginning (only when there's a match), the second command
clips the end. the difference to your program is that my version
ignores all previous AUTOFS_USER= options while yours ignores
all further such options. btw, may I suggest adding ">" at the
end of the grep (of course with grep being replaced by egrep)?
if some new version of mount would introduce the mount-option
AUTOFS_USERS or something, your grep would give a false positive...

what my version also doesn't do is to count to 20. is that really
needed? if it is, then your script does depend too much on the
particular version of mount...

P
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-chat
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to