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: John McKown
Subject: Re: Sourcing a file ending in \<newline> disables aliases for 1 command
Date: Fri, 3 Apr 2015 07:19:57 -0500

On Thu, Apr 2, 2015 at 4:40 PM, Pedro Gimeno
<pgwr-842@personal.formauri.es> wrote:
> Bash Version: 4.2
> Patch Level: 37
> Release Status: release
>
> Description:
>         If a file with a command that ends in \<newline> is sourced, the next
> command issued in the command line does not interpret aliases but
> subsequent ones do. It's a minor issue easy to work around, but since
> it's surprising behaviour and some aliases are important, I thought I'd
> report it. In the real case where I used it, the command was 'rm' which
> was an alias to 'rm -i' to ask for confirmation, and it didn't ask.
>
> Repeat-By:
>         $ alias hi=echo\ hello
>         $ echo /bin/true\\ > testbug.sh
>         $ hi
>         hello
>         $ source testbug.sh
>         $ hi
>         bash: hi: command not found
>         $ hi
>         hello
>

Interesting. does the same on my system, but notice something in the
following cut'n'paste

[tsh009@it-johnmckown-linux junk]$ echo /bin/true\\ >testbug.sh
[tsh009@it-johnmckown-linux junk]$ od -tcx1 testbug.sh
0000000   /   b   i   n   /   t   r   u   e   \  \n
         2f  62  69  6e  2f  74  72  75  65  5c  0a
0000013

Note that testbug.sh does end in a LF, at least if I did it correctly.
Also notice in the following transcript:

[tsh009@it-johnmckown-linux junk]$ echo -n /bin/true >|testbug.sh
[tsh009@it-johnmckown-linux junk]$ od -tcx1 testbug.sh
0000000   /   b   i   n   /   t   r   u   e
         2f  62  69  6e  2f  74  72  75  65
0000011
[tsh009@it-johnmckown-linux junk]$ source testbug.sh
[tsh009@it-johnmckown-linux junk]$ hi
hello
[tsh009@it-johnmckown-linux junk]$

In this case, testbug.sh truly does NOT have an LF at the end, and
there is no problem.

Also notice, all by itself, not preceded by the source command:

[tsh009@it-johnmckown-linux junk]$ \hi
bash: hi: command not found...
[tsh009@it-johnmckown-linux junk]$

Also notice:

[tsh009@it-johnmckown-linux junk]$ "hi"
bash: hi: command not found...

Which is expected since enclosing the command in ".." is "quoted",
which disables expanding aliases

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.


-- 
If you sent twitter messages while exploring, are you on a textpedition?

He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown



reply via email to

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