help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to understand "set --"?


From: Chris Down
Subject: Re: [Help-bash] How to understand "set --"?
Date: Wed, 19 Feb 2014 12:31:22 +0800
User-agent: Mutt/1.5.22 (2013-10-16)

On 2014-02-18 22:12:26 -0600, Peng Yu wrote:
> "help set" says
> 
>       --  Assign any remaining arguments to the positional parameters.
>           If there are no remaining arguments, the positional parameters
>           are unset.
> 
> 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
> ~/linux/test/bash/man/builtin/set/--$ printf "%s\n" "$@"
> 'abc
> def'

I don't know where you got the impression that -- should change the
normal actions of word splitting. That's not what the manual reads as
saying to me, it seems quite clear about how it operates (in the same
way that many POSIX tools operate).

set -- just avoids the case where there are positional parameters that
begin with a dash:

    $ printf '<%q>\n' "$@"
    <''>
    $ set -H  # turn history expansion on
    $ printf '<%q>\n' "$@"
    <''>
    $ set -- -H  # set $1 to "-H"
    $ printf '<%q>\n' "$@"
    <-H>

Attachment: pgpVLpaoWDZQU.pgp
Description: PGP signature


reply via email to

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