bash 脚本中的查找命令不起作用

Find command in a bash script not working

我有一个 bash 读取作为输入的文件夹名称列表(所有数字不是字母)并尝试找到每个文件夹的位置。 Find 命令对我来说根本没有 return 任何东西。我不知道为什么。而如果我在不使用变量的情况下输入原始值,它就可以工作。

代码:

    #!/bin/bash
filename='bat.txt'
n=1
while read line;
do
lien=$(find ./ -type d -name "$line")
# for read each line
echo "line no. $n : $line"
n=$((n+1))
done < $filename

Bat.txt 样本:

19223
12233
34434
34434

根据评论提供的额外信息,解决方案应该是更正脚本中的拼写错误:

#!/bin/bash
filename='bat.txt'
n=1
while read line;
do
line=$(find ./ -type d -name "$line")
# for read each line
echo "line no. $n : $line"
n=$((n+1))
done < $filename

并将 bat.txt 的行尾从 Windows/DOS 转换为 Linux/Unix

sed -i 's/\r$//' bat.txt 

可以找到有关此问题的更多信息 , various alternatives to perform the conversion can be found here