执行 shell 脚本时找不到 fc
fc not found when executing a shell script
我有以下 shell 脚本 zsh_history_fix.sh:
# Fixes a corrupt .zsh_history file
mv ~/.zsh_history ~/.zsh_history_bad
strings ~/.zsh_history_bad > ~/.zsh_history
fc -R ~/.zsh_history
rm ~/.zsh_history_bad
任何时候我尝试执行 ./zsh_history_fix.sh
,它都会抛出 ./zsh_history_fix.sh: 4: fc: not found
。
知道为什么我会收到此错误吗?
仅供参考:
fc 似乎只是 zsh 的内置命令。
我猜你没有在文件顶部添加 #!/bin/zsh ,
所以 shell 将默认在 bash 环境中执行。
因此终端给你错误 fc: not found.
解决
在第一行添加#!/bin/zsh
我有以下 shell 脚本 zsh_history_fix.sh:
# Fixes a corrupt .zsh_history file
mv ~/.zsh_history ~/.zsh_history_bad
strings ~/.zsh_history_bad > ~/.zsh_history
fc -R ~/.zsh_history
rm ~/.zsh_history_bad
任何时候我尝试执行 ./zsh_history_fix.sh
,它都会抛出 ./zsh_history_fix.sh: 4: fc: not found
。
知道为什么我会收到此错误吗?
仅供参考: fc 似乎只是 zsh 的内置命令。 我猜你没有在文件顶部添加 #!/bin/zsh , 所以 shell 将默认在 bash 环境中执行。 因此终端给你错误 fc: not found.
解决
在第一行添加#!/bin/zsh