I'm very new in bash script and I wrote a code to compare an entered file with the files in a directory named new2 but i get the following error:
line 8: [~/new1/file1: No such file or directory
here is my code:
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
can any one help me to fix this? thanks in advance!
if ["~/new1/$input" -ef $F] ;then
您需要在两个方括号前后放置一个空格
if [ "~/new1/$input" -ef $F ] ;then
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.