
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')
das ist, was ich bekomme, wenn ich das folgende Skript im Terminal ausführe
#!/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
er kann das Escape-Zeichen "\" nicht analysieren, das wegen der Anführungszeichen in Zeile 8 verwendet werden muss gnomeTab+=" --tab -e \"cpulimit -p $i -l $limitationPercentage \" "
. Gibt es also eine Lösung, die Anführungszeichen zu verwenden, da diese danach zwingend erforderlich sind --tab -e " some commands "
, um das Analyseproblem zu vermeiden?
Antwort1
Sie können die allererste Zeile ändern in
#!/bin/bash -xv
damit die Shell Ihnen zeigt, wie sie Argumente interpretiert.
Anstatt zu entkommen (was zu führt eval
), sollten Sie Arrays verwenden, um Optionen zu sammeln:
for i in $getAllPIDRunUnderThisProgram ; do
gnomeTab+=(--tab -e "cpulimit -p $i -l $limitationPercentage")
done
echo "${gnomeTab[@]}"