linux - shell中的-f和-e有什么区别?

标签 linux shell unix

shell 中的-f-e 有什么区别?

我知道

-e : To check if the file name exists

-f : To check if a file exists

但是,它们之间有什么区别呢?


编辑:

我特别关注这段代码:

if [ -e test.sh ]; then
    echo "Yes";
else
    echo "No";
fi 

if [ -f test.sh ]; then 
    echo "Yes"; 
else
    echo "No"; 
fi

两者都打印

最佳答案

-f-e 类似,但它还检查名称是否指代普通文件(与目录、套接字等相对)。

参见man 2 statst_mode/S_IFMT的描述获取可能的文件类型列表。

关于linux - shell中的-f和-e有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38007903/

相关文章:

php - 远程端ssh2执行生命周期

linux - 如何将包含私有(private) ssh key 的字符串写入文件?

Python 子进程调用不起作用

linux - 将可执行属性扩展到所有用户

linux - 使用 ffmpeg 合并时调整两个输入 mp3 文件的音量

linux - 如何将带引号的字符串作为参数传递给 bash 中的函数?

python - 解决 bash 脚本中的 sys.excepthook 错误

c - 使用 malloc 时出现无效转换错误

java - 从作为后台作业运行的 shell 脚本生成进程

javascript - 我如何在nodejs中触发 "System Bell"