我正在遍历一个目录,需要找到所有不可执行的文件。我知道
if [ -x $dir ]; then
echo "$dir is an executable file"
fi
显示它是可执行的,但我该如何做相反的事情呢?我试过了
if [ !-x $dir ]; then
echo "$dir is not-executable"
fi
但是这不起作用。
最佳答案
通过 Shell Check 运行线路显示:
if [ !-x $dir ]; then
^-- SC1035: You are missing a required space here.
^-- SC2086: Double quote to prevent globbing and word splitting.
添加缺失的空格和引号会导致:
if [ ! -x "$dir" ]; then
您还可以使用通用语法将 !
放在方括号外 if !命令
,适用于任何命令:
if ! [ -x "$dir" ]; then
关于bash - 如何确定文件是否不可在 bash 脚本中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66554145/