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]