0

how can I execute in a correct way a python script that has many parameter within a bash script?

I have tried this:

#!/bin/bash

CMD="/home/blabla.py --spec standard --id blabla --type car --wait 6 --priority normal --custom ' --tag blabla&&!klingklong --conf /home/team/blabla.yaml ' "
$CMD

Note: the above command is example with parameter values as they are created in previous steps of the bash script. I reality the command looks like this:

CMD="/home/blabla.py --spec ${SPEC} --id ${ID} --type ${TYPE} --wait ${WAIT} --priority ${PRIORITY} --custom ' --tag blabla&&!klingklong --conf /home/team/blabla.yaml ' "

So, I first create all the command end then I am trying to execute it. In a next step I would even add variable for --tag and --conf.

If I copy the command and I execute it directly in a shell it will execute without any issues. But executing the bash script it complains about the parameters in --custom which are in ''.

What I have observed is that when executing in shell the --custom parameters are acknowledged and correct add to a variable custom of the /home/blabla.py

custom=' --tag blabla&&!klingklong --conf /home/team/blabla.yaml'

But this does not happen when executing from a bash script!

blabla.py: error: unrecognized arguments: --tag blabla&&!klingklong --conf /home/team/blabla.yaml '

I notice that at the above error printout I see at the end "'"

Any idea? Do I need to escape any character or use double brackets?

FotisK
  • 877
  • 2
  • 11
  • 23
  • The short answer is "don't store the command in a variable"; why would you want to do that, anyway? You will also need to add quotes around shell metacharacters like `&`; see [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Oct 14 '21 at 11:05

0 Answers0