【发布时间】:2018-10-18 08:40:58
【问题描述】:
下面是一个简单的脚本,用于确定所有文件是否存在并且大小是否大于零。从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。
【问题讨论】:
-
右方括号之间需要一个额外的空格。
if [ -s ${file1} && -s ${file2} && -s ${file3} ]; -
我尝试添加额外的空间。现在错误是 ./temp.ksh[]: [: ']' missing Between.... echo 至少应该可以工作。
标签: linux shell ksh file-handling