我有一個shell腳本讀取數組中的文件。它與RHEL完美協作,但是當我在Ubuntu上運行相同的腳本時,出現錯誤。這是腳本。如何使用shell腳本讀取數組中的文件內容?
file=/root/monitor.txt
while IFS=',' read -ra line ; do
echo -e "export MASTER_IP=${line[2]}" >> ~/.bashrc
source ~/.bashrc
done < $file
上述腳本在RHEL中完美工作。當我在Ubuntu上運行它,我得到的錯誤是
read: Illegal option -a
'-a'選項僅用於bash。查看本頁[Unix - 使用Shell數組](http://www.tutorialspoint.com/unix/unix-using-arrays.htm)以供參考。 – fedorqui 2014-09-02 08:25:56
對於純粹的POSIX sh,數組不存在 - 它們是bash,zsh等採用的ksh特性。幸運的是,您不需要它們。 – 2014-09-03 12:06:58