0
我想在我的Mac上寫一個bash腳本,它讀取文件的內容,並使用它讀取的每一行來組裝一個路徑然後cd到它並在那裏做一些命令。以下是我嘗試的腳本:bash腳本從文件中讀取目錄,然後cd到他們失敗
#!/bin/bash
repo="$HOME/sp16-cs233"
cat file.txt | while read line
do
cd $repo/$line
#do some stuff here
done
該文件包含位於repo路徑下的文件夾的名稱。當我嘗試運行此我得到以下錯誤:
wirelessprvnat-172-17-237-248:Honors adelejjeh$ ./script.sh
: No such file or directorysers/adelejjeh/sp16-cs233/albers3
: No such file or directorysers/adelejjeh/sp16-cs233/jablum2
: No such file or directorysers/adelejjeh/sp16-cs233/iwchen2
: No such file or directorysers/adelejjeh/sp16-cs233/durg2
: No such file or directorysers/adelejjeh/sp16-cs233/hgao17
: No such file or directorysers/adelejjeh/sp16-cs233/agoel9
: No such file or directorysers/adelejjeh/sp16-cs233/eshoag2
: No such file or directorysers/adelejjeh/sp16-cs233/jinglim2
: No such file or directorysers/adelejjeh/sp16-cs233/gluo2
: No such file or directorysers/adelejjeh/sp16-cs233/ypark92
: No such file or directorysers/adelejjeh/sp16-cs233/hequ2
: No such file or directorysers/adelejjeh/sp16-cs233/dssheph2
出於某種原因,當腳本運行錯誤的事情正在發生的路徑。有任何想法嗎?