I am in GNU bash version 4.3.11.
Say I want to print unique lines in a file. I use this approach, which works well in a file:
$ cat a 9 10 9 11 $ awk '!seen[$0]++' a 9 10 11
However, if I get input from stdin using double quotes in multi-line and piping to awk, this fails:
$ echo "9 > 10 > 9 > 11" | awk '!seen[$0]++' bash: !seen[$0]++': event not found
That is, bash is trying to deploy the seen command, which of course does not know, because it is the name of the variable. But this should not happen, because the command is placed in single quotes.
echo on single-line multi-line input works well:
$ echo '9 > 10 > 9 > 11' | awk '!seen[$0]++' 9 10 11
The funny thing is that it also works well on single-line input, which is quoted twice:
$ printf "9\n10\n9\n11" | awk '!seen[$0]++' 9 10 11
I wonder why bash tries to expand the story if it occurs after mutiline is entered, although the command itself uses single quotes.
Other considerations:
Having a pipe between them, she does not correct:
$ echo "9 > 10 > 9 > 11" | cat - | awk '!seen[$0]++' bash: !seen[$0]++': event not found
And setting set +H disables the story , so it works well because it is not trying to expand anything:
$ set +H $ echo "9 > 10 > 9 > 11" | awk '!seen[$0]++' 9 10 11
I reviewed the rici canonical answer on how to address the error "bash :! d ': event not found" in bash command substitution and found many possible causes, but none of them matches this behavior.
bash gnu command-substitution
fedorqui
source share