Bash - 文件存在不起作用

时间:2016-10-13 17:30:57

标签: bash file-exists

我有一个包含文件列表的文件,我想知道这些文件是否存在。我用了这个命令:

while read line; do 
    filename="$(echo $line | cut -d';' -f4)"; 
    if [ ! -e "/some/path/$filename" ]; 
    then echo "/some/path/$filename"; 
    fi ; 
done < "../my_list_of_file"

此命令将返回列为不存在的每个文件,例如:

/some/path/my_listed_file.jpg

但是当我ls /some/path/my_listed_file.jpg时,我可以看到该文件存在。我的命令有什么问题?

1 个答案:

答案 0 :(得分:1)

Thank you to Barmar and chepner, the problem was the CRLF on the end of the file. Here is the working command :

while IFS=$';\r' read -r _ _ _ filename _; do 
    if [ ! -e "/some/path/$filename" ]; 
    then echo "/some/path/$filename"; 
    fi ; 
done < "../my_list_of_file"
相关问题