我想讀取變量中的整個文件。例如我的文件是 。bash腳本將整個文件讀入一個帶有換行符的變量
文件名:Q.txt
My name is Naeem Rehmat.
I am a student of FAST university.
Now i am in 4th semester.
I am learning bash script.
I have this problem.
代碼:
text=$(cat Q.txt)
echo $text
出認沽應該是這樣的:
My name is Naeem Rehmat.
I am a student of FAST university.
Now i am in 4th semester.
I am learning bash script.
I have this problem.
也許在發佈之前檢查['bash' tag wiki](http://stackoverflow.com/tags/bash/info)。 – tripleee
根據評論,我不認爲鏈接的問題是重複的。我相信這裏的問題是關於流程替換消除了尾隨的換行符的事實,但它並不十分清楚。請注意,我編輯了問題,將樣式添加到示例輸入中,並且(我認爲)Naeem圍繞輸入文件中的尾部空白行進行了旋轉。 Naeem,你需要澄清,因爲你的問題不清楚。 –