bug-bash
[Top][All Lists]
Advanced

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

Re: Is this an IFS bug in getopts?


From: Greg Wooledge
Subject: Re: Is this an IFS bug in getopts?
Date: Tue, 26 Apr 2011 12:58:38 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Apr 26, 2011 at 12:41:49PM -0400, Steven W. Orr wrote:
> >>It turns out that when I
> >>called getopts, I had set IFS='-'.

I assume you mean "when I called die".

> die()
> {
>     typeset opt
>     typeset opt_s=1
>     typeset opt_i=0
>     typeset err_opts=
>     OPTIND=1
>     while getopts ':is:' opt "$@"
>     do
>         case $opt in
>         i)
>             opt_i=1
>             err_opts='-i'
>             ;;
>         s)
>             opt_s=$OPTARG
>             ;;
>         *)
>             err "Illegal option to die: ${@:((OPTIND-1)):1}"
>             exit 1
>             ;;
>         esac
>     done
>     shift $((OPTIND-1))
>     err $err_opts -- "$@"
>     exit $opt_s
> }

You have an unquoted $err_opts in this function, so IFS will certainly
affect that.

Let's suppose you are trying to end up with:

err_opts='-i'
...
err -i -- "$@"

But:

imadev:~$ IFS=-
imadev:~$ err_opts='-i'
imadev:~$ echo $err_opts
 i



reply via email to

[Prev in Thread] Current Thread [Next in Thread]