My zsh is replacing !~
with a command I previously ran. This is a problem because when I run awk '$1 !~ /abc/
, it replaces the !~
with the command.
Any idea on how to disable this? It's possible it's not zsh's fault, but after googling for an hour and not finding anything I decided it was the most likely candidate.
UPDATE:
This only happens when !~
occurs on a newline:
echo !~
# ~/bin/test_translate.rb
echo foo | awk '
$1 !~ /abc/'
awk: cmd. line:2: $1 ~/bin/test_translate.rb /abc/
awk: cmd. line:2: ^ syntax error
awk: cmd. line:3: $1 ~/bin/test_translate.rb /abc/
awk: cmd. line:3: ^ unexpected newline or end of string
UPDATE 2:
I've narrowed it down to this line in my .zshrc
:
source $ZSH/oh-my-zsh.sh
I would like to find out what option is making zsh
replace !~
plus spacebar into the last path I accessed, but I don't want to stop using oh-my-zsh. I haven't manually modified $ZSH/oh-my-zsh.sh
.
In zsh (and some other shells) !
triggers the history expansion (see man zshexpn
section "HISTORY EXPANSION"). In the case of !~
zsh will look for the most recent command starting with ~
.
If you do not use history expansion in any way, you can just disable it by adding this to your .zshrc
setopt nobanghist
Usually history expansion is not done inside single quoted strings, so it should not affect your awk command in any way:
$ echo !~
~/docs
$ echo foo | awk '
$1 !~ /abc/'
foo
On the other hand, inside double quotes history expansion is done and you get the mentioned error message:
$ echo !~
~/docs
$ echo foo | awk "
$1 !~ /abc/"
echo foo | awk "
$1 ~/docs /abc/"
awk: cmd. line:2: ~/docs /abc/
awk: cmd. line:2: ^ syntax error
awk: cmd. line:3: ~/docs /abc/
awk: cmd. line:3: ^ unexpected newline or end of string
So, if the problem can be traced to source $ZSH/oh-my-zsh.sh
, I'd guess that Oh, my ZSH does something to break the way zsh handles quoting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With