0

Goal:

Run gnome-terminal -e "npm run start --prefix /home/cc/Desktop/Programming/Software/Elastic/elasticsearch-head"

Code:

HEAD="gnome-terminal -e \"npm run start --prefix /home/cc/Desktop/Programming/Software/Elastic/elasticsearch-head\""
${HEAD}

Error:

Failed to parse arguments: Argument to "--command/-e" is not a valid command: Text ended before matching quote was found for ". (The text was '"npm')

Additional info:

When I try to use

ES="gnome-terminal -e \"/home/cc/Desktop/Programming/Software/Elastic/pna/bin/elasticsearch\""
${ES}

then it works without problem. The difference is that [...]/bin/elasticsearch is a shell script itself, while npm run start is supposed to run the programm npm with the arguments run start. But with my non-existing knowledge of Bash I'm not able to solve this.

Thanks for any suggestions!

ss1
  • 1,009
  • 15
  • 32

1 Answers1

2

Quotes are always used by shell interpreter to detect and protect words. They never be included into the the result

Therefore use an array:

HEAD=( gnome-terminal -e "npm run start --prefix \
    /home/cc/Desktop/Programming/Software/Elastic/elasticsearch-head" )
"${HEAD[@]}"
Wiimm
  • 2,971
  • 1
  • 15
  • 25
  • works, thanks. There is a parenthesis missing at the end of the array. Can't edit your reply, because the edit is blocked for being too short. – ss1 Feb 02 '19 at 10:19
  • Closing parenthesis added! – Wiimm Feb 02 '19 at 10:20