Re: Multi-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped to
On 6/14/16 8:52 AM, Néstor Tejero wrote: > When printing a multi-line string and piping to another command that uses > single-quotes, Bash tries to perform history expansion: > > echo "9 >> 10 >> 9 >> 11" | awk '!seen[$0]++' > bash: !seen[$0]++': event not found History expansion is explicitly line-oriented. It doesn't know about shell state, especially shell quoting state, that spans lines. It does know about vaguely shell-like quoting that's common across a large set of Unix utilities -- since the history and readline libraries are used outside the shell -- and that a double quote introduces a quoted string in which single quotes are not significant and don't inhibit history expansion. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Multi-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped to
Hello, This is my system: $ bash --version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) $ uname -a Linux PCNTEJERO 3.19.0-51-generic #58~14.04.1-Ubuntu SMP Fri Feb 26 22:02:58 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux ntejero@PCNTEJERO: ~ $ cat /etc/*ease DISTRIB_ID=LinuxMint DISTRIB_RELEASE=17.3 DISTRIB_CODENAME=rosa DISTRIB_DESCRIPTION="Linux Mint 17.3 Rosa" NAME="Ubuntu" VERSION="14.04.4 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.4 LTS" VERSION_ID="14.04" HOME_URL="http://www.ubuntu.com/; SUPPORT_URL="http://help.ubuntu.com/; BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/; cat: /etc/upstream-release: Is a directory Bash was installed through "apt-get install --only-upgrade bash" The bug: When printing a multi-line string and piping to another command that uses single-quotes, Bash tries to perform history expansion: echo "9 > 10 > 9 > 11" | awk '!seen[$0]++' bash: !seen[$0]++': event not found > $ echo "9 > 10 > 11" | echo '!a' bash: !a': event not found > Turning history off solves it, but anyway history expansion should not occur within single-quotes. This does not happen in single lines: $ printf "23\n24\n25" | echo '!a' !a Néstor