
Failed to parse arguments: Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for ". (The text was '"cpulimit')
ターミナルで次のスクリプトを実行すると、次の結果が得られます。
#!/bin/bash
read -p "Which program u want to limit its processes?" ProgrameName
read -p "Which limitation percentage u want for it ?" limitationPercentage
getAllPIDRunUnderThisProgram=$( ps -e | grep "$ProgrameName" | awk '{print $1;}')
for i in $getAllPIDRunUnderThisProgram
do
gnomeTab+=" --tab -e \"cpulimit -p $i -l $limitationPercentage \" "
done
gnome-terminal $gnomeTab
8 行目の二重引用符のせいでエスケープ文字「\」を使用しなければならないのですが、解析できません。解析の問題gnomeTab+=" --tab -e \"cpulimit -p $i -l $limitationPercentage \" "
が発生しないように、必ず二重引用符を使用するという解決策はありますか--tab -e " some commands "
?
答え1
最初の行を次のように変更することができます
#!/bin/bash -xv
シェルが引数をどのように解釈するかを表示します。
エスケープするのではなく ( につながるeval
)、配列を使用してオプションを蓄積する必要があります。
for i in $getAllPIDRunUnderThisProgram ; do
gnomeTab+=(--tab -e "cpulimit -p $i -l $limitationPercentage")
done
echo "${gnomeTab[@]}"