我試圖cat
文件名爲file sth.txt
。當我寫如何在BASH中用文件名中的空格創建文件?
cat "file sth.txt"
它很好用。
當我保存file sth.txt
爲可變file
和我執行
cat "$file"
系統寫入
cat: file: No such file or directory
cat: sth.txt: No such file or directory
我想cat
文件與變量,並在它不止一個文件名。對於沒有空間的文件名,它的作品。任何人都可以給我一些建議嗎?
你使用'cat「$ file」'還是'cat $ file'?因爲引用的版本應該可以正常工作。 – 2015-04-03 17:51:52
如果我在變量中有多個文件,那麼這是行不通的。我該怎麼做? – 2015-04-03 18:11:57
如果您的變量包含多個文件名,那麼您不能在名稱中使用空格支持文件。不要在同一個變量中放置多個文件名。使用一個數組或多個參數。 – 2015-04-03 18:13:14