首页 > 解决方案 > Shell 脚本回显问题

问题描述

在 shell 脚本的这个 if 条件下,我想打印用户全名 + 存在(如果文件 ..../pub_key.asc 找到)或者如果找不到提到的文件则不存在

for file in $FILES
do
if [ -f  /home/$file/public_html/pub_key.asc ]; then
     echo $(cat /home/$file/etc/passwd | head -n | cut -d: -f1) : Exists
else
    echo  $(cat /home/$file/etc/passwd | head -n | cut -d: -f1) : Not exists!
fi
done

但我收到错误,因为 if..condition 中的第一个回显有问题。有人可以告诉我我在 echo 声明中做了什么吗?以及如何解决?感谢您的建议。:)

标签: linuxbashshellecho

解决方案


由于head -n命令,您可能会遇到错误

head -n必须后跟一个数字,例如head -n 1head -1


推荐阅读