我有一個文件包含兩個目錄路徑(將包含更多)。我想閱讀每一行,然後在每行上做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