[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to understand "set --"?
From: |
Eric Blake |
Subject: |
Re: [Help-bash] How to understand "set --"? |
Date: |
Tue, 18 Feb 2014 21:28:35 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
On 02/18/2014 09:12 PM, Peng Yu wrote:
> Hi,
>
> "help set" says
>
> -- Assign any remaining arguments to the positional parameters.
> If there are no remaining arguments, the positional parameters
> are unset.
Let's say you want to have $1 contain a literal "-x". You do this by
either:
set dummy -x; shift # portable to really old pre-POSIX sh
or by:
set -- -x # portable to all POSIX shells
The -- said to treat the next argument as the thing to place in $1, even
if that argument would normally be treated specially by set if the --
were not present.
>
> But it seems that the above definition is not clear enough to explain
> the following output. Can anybody provide a better definitive
> explanation of "set --"? Should it be better to interpret the single
> quote in $x when "set --" is called?
>
> ~/linux/test/bash/man/builtin/set/--$ x="'abc def'"
> ~/linux/test/bash/man/builtin/set/--$ set -- $x
Underquoted. You called:
set -- "'abc" "def'"
because you forgot to quote $x. The rules about -- do not change the
rules about quoting, only about whether a leading - is interpreted by
set as an option instead of crammed into $1.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature