我有一个文件包含两个目录路径(将包含更多)。我想阅读每一行,然后在每行上做ls
。很简单的权利?For循环,需要输入文件不工作
事情是不工作,我不知道为什么。无论我做什么,最后一行总是很好,ls
。之前的行是“不”存在于ls
,即使它们存在。
的File.List
/path/to/directory1/
/path/to/directory2/
/path/to/directory1/
/path/to/directory2/
当我运行下面的代码片段
DIRECTORIES="file.list"
for DIR2 in `cat $DIRECTORIES`
do
echo $DIR2
ls $DIR2
done
我得到的输出
/path/to/directory1/
does not exist. file /path/to/directory1/
/path/to/directory2/
does not exist. file /path/to/directory2/
/path/to/directory1/
does not exist. file /path/to/directory1/
/path/to/directory2/
Server
下面有什么不对呢?其他更好的解决方案?
感谢
编辑:奇怪,我只是试图在另一个Unix机器和工作得很好
行确实有在该行的最后一些奇怪的字符并工作。我试着用你的方法去除'$ DIR2 = \'echo $ DIR2 | tr -d'[\ n \ r]'\''但没有工作 – esausilva
我犯了一个错字,很抱歉。尝试使用更新后的代码行(左侧没有美元符号)。我已经更新了答案。 – alexander