1
我有一個數組。在數組中存儲可執行的行選項
ARR=("option1" "option with space" "option3")
如果我以這種方式
executable "option1" "option with space" "option3"
運行的可執行這是我怎樣才能做到這一點?
我有一個數組。在數組中存儲可執行的行選項
ARR=("option1" "option with space" "option3")
如果我以這種方式
executable "option1" "option with space" "option3"
運行的可執行這是我怎樣才能做到這一點?
您可以運行它像這樣:
arr=("option1" "option with space" "option3")
executable "${arr[@]}"
只需通過數組的內容爲可執行文件,
<executable> "${ARR[@]}"
雙擊引用數組的內容是很重要的位置,並失去它會讓選項留有空格。
用一個例子的圖: -
dudeOnMac:~$ touch file
dudeOnMac:~$ touch "file with spaces"
dudeOnMac:~$ ls
file file with spaces
dudeOnMac:~$ touch "[email protected]"
dudeOnMac:~$ ls
file file with spaces [email protected]
dudeOnMac:~$ fileList=("file" "file with spaces" "[email protected]")
dudeOnMac:~$ ls "${fileList[@]}"
file file with spaces [email protected]
dudeOnMac:~$ ls -1tr "${fileList[@]}"
file
file with spaces
[email protected]