Linux 编写程序检查给定文件是否存在

Linux 编写程序检查给定文件是否存在,linux,Linux,此程序给我错误信息 echo enter the file name read fname If [-a $fname] then echo "$num is negative" else echo "cannot find a file" 错误是: bsccs.sh: line 3: [-a: command not found cannot find a file 您需要一个空间: if [ -a $fname ] 此外,“If”无效。必须是小写。此问题是由于无法再复制的

此程序给我错误信息

echo enter the file name
read fname
If [-a $fname] 
then
   echo "$num is negative"
else
   echo "cannot find a file"
错误是:

bsccs.sh: line 3: [-a: command not found
cannot find a file
您需要一个空间:

if [ -a $fname ]

此外,“If”无效。必须是小写。

此问题是由于无法再复制的问题或简单的印刷错误造成的。虽然类似的问题可能在这里的主题,这是一个解决的方式不太可能帮助未来的读者。这通常可以通过在发布前确定并仔细检查重现问题所需的最短程序来避免。