首页 > 解决方案 > 执行 shell 脚本时找不到 fc

问题描述

我有以下 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. 知道为什么我会收到此错误吗?

标签: shellubuntuterminalwindows-subsystem-for-linux

解决方案


仅供参考: fc 似乎只是 zsh 的内置命令。我猜你没有在文件顶部添加#!/bin/zsh,所以shell默认会在bash环境中执行。因此终端给你错误 fc: not found。

解决

在第一行添加#!/bin/zsh


推荐阅读