dot*_*ode 2 unix awk printf zsh
在bash中,我可以执行以下操作:
$ printf "foo\nbar\n" | awk '{printf "%s\n", $1}'
foo
bar
Run Code Online (Sandbox Code Playgroud)
...但是在我做同样的zsh时,我得到了这个:
$ printf "foo\nbar\n" | awk '{printf "%s\n", $1}'
[m\n", printf}'foo
bar
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
你有没有机会使用oh-my-zsh?$()
由于自动终端标题设置中的快速扩展,终端设置中存在一个错误,导致它在printf和date(以及子命令!)等命令中评估%-tags .
查看~/.oh-my-zsh/termsupport.sh
并应用此更改:
*** termsupport.zsh.orig 2012-01-31 10:49:57.503119973 +0100
--- termsupport.zsh 2012-01-31 10:50:55.043118110 +0100
***************
*** 24,31 ****
function omz_termsupport_preexec {
emulate -L zsh
setopt extended_glob
! local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
! title "$CMD" "%100>...>$2%<<"
}
autoload -U add-zsh-hook
--- 24,35 ----
function omz_termsupport_preexec {
emulate -L zsh
setopt extended_glob
! local CMD_1=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
! local CMD_2=${2//\$\(/\\\$(} # ')}
! CMD_1=${CMD_1//\%/%%}
! CMD_2=${CMD_2//\%/%%}
! #
! title "${CMD_1}" "%100>...>${CMD_2}%<<"
}
autoload -U add-zsh-hook
Run Code Online (Sandbox Code Playgroud)
(对应的omz-issue https://github.com/robbyrussell/oh-my-zsh/issues/890)