linux - 在 KornShell 中检查大小大于零的多个文件

标签 linux shell ksh file-handling

下面是一个简单的脚本,用于查明所有文件是否存在以及大小是否大于零。来自 here我知道“-s”用于该任务。

if [ -s ${file1} && -s ${file2} && -s ${file3}]; then
   echo "present"
   echo "Perform analysis"
else
   echo "not present";

   echo "Value of file1: `-s ${file1}`"
   echo "Value of file2: `-s ${file2}`"
   echo "Value of file3: `-s ${file3}`"
   echo "skip";
fi

这些文件位于与脚本相同的路径中。我检查了文件名,它是正确的。我收到以下错误:

./temp.ksh[]: [-s: not found [No such file or directory]
not present
./temp.ksh[]: -s: not found [No such file or directory]
Value of file1:
./temp.ksh[]: -s: not found [No such file or directory]
Value of file2:
./temp.ksh[]: -s: not found [No such file or directory]
Value of file3:

我似乎无法找出上面的问题所在。这是 KornShell 特有的吗?我只能用KSH。

最佳答案

引用this问题的答案。错误是在 if 语句中使用 [ ] 而不是 [[ ]],因为 [[ ]] 可以解释 && 但 [ ] 不能。

关于linux - 在 KornShell 中检查大小大于零的多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52870153/

相关文章:

c - 如何从C文件中获取所有指针变量

bash - 从shell脚本中的文件名中删除一级文件扩展名

linux - 如何在 bash 的每个子目录中创建相同的目录?

linux - App Engine 忽略指向目录的符号链接(symbolic link)

mysql - 无法在 Mac OS 10.9.2 上启动 mysql

shell - 排序科学和 float

linux - 运行 cron 产生的结果与运行它的命令不同

linux - IFS 和命令替换

shell - KSH Shell 双变量名称?

linux - Linux 上有效的 suid/sgid 可执行文件列表?