Date:        Tue, 15 Jan 2019 09:46:20 -0500
    From:        Chet Ramey <[email protected]>
    Message-ID:  <[email protected]>

  | Which shells don't rescan the alias value in the lexer? AFAICT, that's one
  | of the things everyone does the same way.

And the proposed resolution says they should, the part that is (apparently) 
not done the same way always is "prepending the expanded string to the input"
which results in the final character of the alias value being adjacent to the
character whiich delimited the alias name, with the potential that the two 
become part of the same word (if the alias string contained an unbalanced
quote character) or operator (if the alias value ends '>' and the delimiting
character was '&' we get the '>&' redirect operator for example).

As for which shells don't do it, or do it differently, .well, bash is one ...

magnolia$ echo $BASH_VERSION
4.4.12(1)-release
magnolia$ alias foo='echo "x'
magnolia$ foo bar"
x  bar
magnolia$ 

Notice two spaces between the 'x' and 'bar' in the output, if it acted
exactly as described, it would have only one, as the expanded input
to be rescanned would be
        echo "x bar"
I don't have bash 5 yet to check that one.

For the other example in the proposed new wording...

jinx$ dash
$ alias foo='sleep 3&'
$ foo&:
dash: 2: Syntax error: "&" unexpected
$ 

where other shells (bash included) treat that as "sleep &&:"
yet dash does the previous example "correctly".

The FreeBSD shell does the same as bash in the first example,
and dash in the second, which at least is consistent processing,
unlike the bash & dash.

As a comparison -- using the very latest NetBSD shell, with
all the alias bugs we used to have (that I am aware of anyway)
fixed -- This same version is in NetBSD HEAD, except that one
would not have the DEBUG word in the version string.   Older
NetBSD shells are full of alias related bugs and aren't worthy
of any consideration at all.


[jinx]$ echo $NETBSD_SHELL
20181212 DEBUG
[[jinx]$ alias foo='echo "x'
[jinx]$ foo bar"
x bar
[jinx]$ alias foo='sleep 3&'
[jinx]$ date; foo&: ; date
Wed Jan 16 04:45:32 +07 2019
Wed Jan 16 04:45:35 +07 2019

ksh93, bosh, mksh, pdksh, all give the same results.

krre



Reply via email to