仅当我通过执行 触发全局扩展时,脚本的第二行才有效echo
。我不明白为什么。这是命令及其执行情况以提供一些上下文。
函数定义:
~/ cat ~/.zsh/includes/ascii2gif
ascii2gif () {
setopt extendedglob
input=$(echo ${1}(:a))
_path=${input:h}
input_f=${input:t}
output_f=${${input_f}:r}.gif
cd $_path
nerdctl run --rm -v $_path:/data asciinema/asciicast2gif -s 2 -t solarized-dark $input_f $output_f
}
Run Code Online (Sandbox Code Playgroud)
激活 ascii2gif 函数的函数调试。
~/ typeset -f -t ascii2gif
Run Code Online (Sandbox Code Playgroud)
调试后的函数执行:
~/ ascii2gif ./demo.cast
+ascii2gif:1> input=+ascii2gif:1> echo /Users/b/demo.cast
+ascii2gif:1> input=/Users/b/demo.cast
+ascii2gif:2> _path=/Users/b
+ascii2gif:3> input_f=demo.cast
+ascii2gif:4> output_f=demo.gif
+ascii2gif:5> cd /Users/b
+_direnv_hook:1> trap -- '' SIGINT
+_direnv_hook:2> /Users/b/homebrew/bin//direnv export zsh
+_direnv_hook:2> eval ''
+_direnv_hook:3> trap - SIGINT
+ascii2gif:6> nerdctl run --rm …
Run Code Online (Sandbox Code Playgroud)