linux - 在 bash 脚本中比较两个文件时没有这样的文件或目录错误

标签 linux bash

我是 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/

相关文章:

linux - 获取 shell 命令输出的第一行

linux - 保存和恢复终端内容

bash - 在系统调用中以编程方式触发 shell 的自动完成事件并获取输出

php - 用特殊字符替换字符串

bash - Bash 中的 Null 和空字符串比较

python - 合并目录树的最快方法

c++ - 编译 STL map 插入时出现问题

linux - 链接失败[ld找不到库]

java - 使用脚本从 *.jar 中删除文件

java - 命令行参数有空格的问题