bug-bash
[Top][All Lists]
Advanced

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

Re: FW: multi-line alias executed out of order


From: Piotr Grzybowski
Subject: Re: FW: multi-line alias executed out of order
Date: Thu, 19 Dec 2013 13:04:38 +0100

 I was able to reproduce this, although there is another fix: remove
"source" from the multiline (foo2) alias.
 I did not look at the alias built-in code lately, but it seems that
"source" scripts are put to the stack for later execution and then
taken into account in a first-in-last-out order.

 cheers,
pg


On Wed, Dec 18, 2013 at 4:49 AM, Andrew Martin <address@hidden> wrote:
> Chet & Pierre:
>
> My apologies, the newlines were somehow removed by my email client.
> First, here's a properly formatted pastebin link:
>
> http://pastebin.com/raw.php?i=AhF89GfT
>
> And here's another attempt at a properly formatted report:
>
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include
> -I../bash/lib  -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector
> --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall
> uname output: Linux ubuntu 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9
> 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 4.2
> Patch Level: 45
> Release Status: release
>
> Description:
> In a multi-line alias, where entries are separated by semi-colon,
> "source" commands are not executed in-step with all the other
> commands.  After all the non "source" commands are executed, the
> "source" commands are executed in reverse order.  See below for an
> example.
>
> Repeat-By:
>
> address@hidden:~$ cat script.sh
> #!/bin/bash
> (echo -n "$1 "; date +%S.%N)
> address@hidden:~$ alias foo1
> alias foo1='~/script.sh one; source ~/script.sh two; source
> ~/script.sh three; ~/script.sh four'
> address@hidden:~$ alias foo2
> alias foo2='~/script.sh one;
> source ~/script.sh two;
> source ~/script.sh three;
> ~/script.sh four;
> '
> address@hidden:~$ foo1
> one 09.742581873
> two 09.745315889
> three 09.749212492
> four 09.761410711
> address@hidden:~$ foo2
> one 11.805819275
> four 11.819741270
> three 11.828260887
> two 11.829470548
>
> Fix:
>
> Use a single-line alias.  Or use the "&&" operator to chain commands
> (which changes the functionality to be short-circuit evaluations).
>
> Also verified this behavior on RHEL6 with bash 4.1.2(1).
>
> Thanks,
> Andrew Martin
>
>
> On Tue, Dec 17, 2013 at 8:41 PM, Andrew Martin <address@hidden> wrote:
>>
>>
>>> Date: Tue, 17 Dec 2013 10:14:23 -0500
>>> From: address@hidden
>>> To: address@hidden
>>> CC: address@hidden; address@hidden; address@hidden
>>> Subject: Re: multi-line alias executed out of order
>>
>>>
>>>
>>> > Description:In a multi-line alias, where entries are separated by
>>> > semi-colon, "source" commands are not executed in-step with all the other
>>> > commands. After all the non "source" commands are executed, the "source"
>>> > commands are executed in reverse order. See below for an example.
>>> > Repeat-By:
>>> > address@hidden:~$ cat script.sh#!/bin/bash(echo -n "$1 "; date
>>> > +%S.%N)address@hidden:~$ alias foo1alias foo1='~/script.sh one; source
>>> > ~/script.sh two; source ~/script.sh three; ~/script.sh 
>>> > four'address@hidden:~$
>>> > alias foo2alias foo2='~/script.sh one;source ~/script.sh two;source
>>> > ~/script.sh three;~/script.sh four;'address@hidden:~$ foo1one 
>>> > 09.742581873two
>>> > 09.745315889three 09.749212492four address@hidden:~$ foo2one
>>> > 11.805819275four 11.819741270three 11.828260887two 11.829470548
>>
>>> > Fix:
>>> > Use a single-line alias. Or use the "&&" operator to chain commands
>>> > (which changes the functionality to be short-circuit evaluations).
>>>
>>> I can't reproduce this on Mac OS X or RHEL 5. You might also consider
>>> adding a few newlines into your report for readability.
>>>
>>> Chet
>>> --
>>> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>>> ``Ars longa, vita brevis'' - Hippocrates
>>> Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/
>



reply via email to

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