linux - 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 声明中做了什么吗?以及如何解决?感谢您的建议。:)
解决方案
由于head -n命令,您可能会遇到错误
head -n必须后跟一个数字,例如head -n 1或head -1
推荐阅读
- c - 从函数中调用函数
- sql - 返回特定于每一列的多个表
- xml - 在 for-each 中填充前导零
- c# - 流畅的 NHibernate 映射 - 执行时列名错误
- jvm - 任何使用 10 GB 系统内存的 JVM 实例
- eclipse - STS4 / Eclipse:nexus + SSL:证书错误
- solidity - 我收到一个解析器错误:remix 中的预期标识符得到了 lparen 构造函数。
- bash - 使用 awk 拆分过滤
- typescript - 防止 TypeScript 在通过函数传递字符串文字类型时将其扩展为字符串类型
- excel - Excel:将值返回到空白单元格之前最后一个匹配字符串的左侧