我试图在目录a中的所有文件中输出总字数,但是当我运行.sh脚本时,我收到错误"找不到命令"在find "$1"...
行。为什么会发生这种情况?如何解决这个问题?
function count_files () {
find "$1" -type f -exec cat {} \+ | wc -w #outputs error here
}
density_a="$(count_files "a")"
答案 0 :(得分:0)
很可能无论哪个用户正在运行该脚本,其路径中都没有查找二进制文件。
尝试使用查找二进制文件的完整路径替换find。 (如果这些工作都不使用“找到”的输出)。
/sbin/find "$1" -type f -exec cat {} \+ | wc -w #outputs error here
或
/bin/find "$1" -type f -exec cat {} \+ | wc -w #outputs error here