bug-bash
[Top][All Lists]
Advanced

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

Re: multi-line alias executed out of order


From: Pierre Gaston
Subject: Re: multi-line alias executed out of order
Date: Tue, 17 Dec 2013 17:14:04 +0200

On Tue, Dec 17, 2013 at 6:33 AM, Andrew Martin <address@hidden>wrote:

> Configuration Information [Automatically generated, do not
> change]:Machine: x86_64OS: linux-gnuCompiler: gccCompilation 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 -Walluname 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/LinuxMachine Type: x86_64-pc-linux-gnu
> Bash Version: 4.2Patch Level: 45Release 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 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).
> Also verified this behavior on RHEL6 with bash 4.1.2(1).
> Thanks!Andrew Martin
>


The missing newlines are like the below?

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

I'm not sure what you mean by multiline aliases?

maybe you wanted to have %s to have a correct timestamp?, %S are just the
seconds.

I cannot reproduce this on RHEL6 with bash 4.1.2(1)

$ cat ~/script.sh
#!/bin/bash
(echo -n "$1 "; date +%S.%N)
$ alias foo1
alias foo1='~/script.sh one; source ~/script.sh two; source ~/script.sh
three; ~/script.sh four'
$ alias foo2
alias foo2='~/script.sh one;source ~/script.sh two;source ~/script.sh
three;~/script.sh four;'
$ foo1
one 29.783807362
two 29.791015625
three 29.798001027
four 29.807617514
$ foo2
one 30.943728979
two 30.950628638
three 30.956146303
four 30.964935789


reply via email to

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