gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:53:32 26 4
gpt4 key购买 nike

下面是一个简单的脚本,用于查明所有文件是否存在以及大小是否大于零。来自 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com