bug-bash
[Top][All Lists]
Advanced

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

Re: Sourcing a file ending in \<newline> disables aliases for 1 command


From: Pedro Gimeno
Subject: Re: Sourcing a file ending in \<newline> disables aliases for 1 command
Date: Sat, 04 Apr 2015 00:39:09 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.7.0

John McKown wrote, On 2015-04-03 14:19:
> Note that testbug.sh does end in a LF, at least if I did it correctly.

I've noticed that actually the LF is not important, only the final
backslash is:

$ alias hi=echo\ hello

Without final LF:

$ echo -n true\\ > testbug.sh
$ . testbug.sh
$ hi
bash: hi: command not found
$ hi
hello

With final LF (same case as initially submitted):

$ echo true\\ > testbug.sh
$ . testbug.sh
$ hi
bash: hi: command not found
$ hi
hello

But if there is one more LF it doesn't reproduce:

$ echo true\\ > testbug.sh
$ echo >> testbug.sh
$ . testbug.sh
$ hi
hello

In the first case the file is malformed, so that's not a problem. I
think the second case should act as if the last command was in a line by
itself without a terminating newline, but that's not what happens. It
can also be argued that in that case the file is malformed too.

In my real use case, the last lines were a set of options to which I was
constantly adding or removing, with a backslash at the end of each line.
At one point I wasn't careful and didn't remove the backslash from the
last line. As I said, the next thing I did was to delete a file, and
that's how I noticed it didn't prompt me for confirmation.

I can easily add a ; in one line alone at the end of the file and insert
the options before it. That'd work around this.

> Since testbug.sh terminates with a \, it appears that the BASH shell
> is "seeing" your second command as \hi. Which _appears to me_ is what
> BASH would call a "quoted value". And it is documented that aliases
> are not expanded when quoted.

On the other hand, this works as expected:

$ echo true\\ > testbug.sh
$ . testbug.sh
$ "hi"
bash: hi: command not found

My point with this last example is that it's not quoting the double
quotes as if they were prefixed with a backslash. This is what happens
when that's the case:

$ \"hi"
>

So it's not as simple as "it acts as if preceded by a backslash".

Also, it doesn't reproduce if the aliased command is inside the sourced
file:

$ echo true\\ > testbug.sh
$ echo hi >> testbug.sh
$ . testbug.sh
bash: truehi: command not found

(which is expected).

$ echo true\\ > testbug.sh
$ echo >> testbug.sh
$ echo hi >> testbug.sh
$ . testbug.sh
hello

(which is expected too).




reply via email to

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