Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: The "-" and "--" options (was Re: ${var:1:1:=y})
On Wed, Feb 4, 2015 at 5:31 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> On 02/04/2015 03:47 PM, Lawrence Velázquez wrote:
>
>> % echo - -
>>
> Ok, the first hyphen gets eaten, and the next one is literal. Still,
> shouldn't
> single quotes make anything inside them literal?
>
The single-quotes simply inhibit the shell from performing any
substitutions (e.g., of $var references) inside the quoted string. The
quotes also inhibit splitting the string on $IFS boundaries; i.e., the
shell will pass the resulting string as a single argument to the command.
The echo command simply gets a hyphen whether or not you quoted it. The
echo command has no way of knowing that it was originally enclosed in
single-quotes.
Ignore for the moment that echo might be a shell builtin. Assume it isn't
and the shell has to search $PATH and invoke the first external command of
that name it finds. You certainly don't want the shell to pass '-' to
/bin/echo. If that was done then every external command would need to
implement the same string parsing that the shell already does. And that way
lie madness. In fact, Microsoft Windows works that way. Or at least it did
back in the MS-DOS through Win98 releases. External commands got a single
string representing all the arguments and it was up to the command to split
the string into tokens and handle any quoting. Ugh!
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Messages sorted by:
Reverse Date,
Date,
Thread,
Author