我是 bash 脚本的新手,我写了一段代码来比较输入的文件和名为 new2 的目录中的文件,但我收到以下错误:
line 8: [~/new1/file1: No such file or directory
这是我的代码:
input=0
while true; do
echo "enter a file name from directory new1 to copy it to directory new2 "
echo "or enter ctrl+c to exit: "
read input
i=0
for F in $(ls ~/new2/) ;do
if ["~/new1/$input" -ef $F] ;then
i=1
break
fi
done
if [ $i -eq 0 ];then
mv ~/new1/$input ~/new2/
echo $input "moved succussfully"
else
echo "file exist"
fi
done
谁能帮我解决这个问题? 提前致谢!
最佳答案
if ["~/new1/$input"-ef $F] ;then
两个括号前后都需要一个空格
if [ "~/new1/$input"-ef $F ] ;then
关于linux - 在 bash 脚本中比较两个文件时没有这样的文件或目录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48585784/