Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
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')

this is what i get when i run the following script in terminal

    #!/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

he cant parse the escape character "\" which it has to be used because of the double quote in line 8 gnomeTab+=" --tab -e \"cpulimit -p $i -l $limitationPercentage \" ",so is there a solution to use the double quote as they are mandatory to be used after --tab -e " some commands " and not to get the problem of parsing ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can change the very first line to

#!/bin/bash -xv

to make the shell show you how it interprets arguments.

Rather than escaping (which leads to eval), you should use arrays to accumulate options:

for i in $getAllPIDRunUnderThisProgram ; do
    gnomeTab+=(--tab -e "cpulimit -p $i -l $limitationPercentage")  
done

echo "${gnomeTab[@]}"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.