0

Is it possible to run something like this:

parent-script.sh "child-script1.sh | child-script2.sh"

and execute $1 inside the parent-script.sh?

...
CMD=$1
...
$CMD
kolisko
  • 1,548
  • 3
  • 17
  • 22
  • 3
    yes, but it is insecure, and you have to be very careful with quoting. The syntax is `eval ...` – jhnc Feb 14 '23 at 13:11
  • 1
    ... and there is almost surely a better way to solve the underlying problem, whatever that might be. – John Bollinger Feb 14 '23 at 14:40
  • 1
    `eval "$CMD"` may do what you want, but see [Why should eval be avoided in Bash, and what should I use instead?](https://stackoverflow.com/q/17529220/4154375). Also note that ALL_UPPERCASE names (like `CMD`) are unsafe in general. See [Correct Bash and shell script variable capitalization](https://stackoverflow.com/q/673055/4154375). – pjh Feb 14 '23 at 14:41
  • Also see [Should I save my scripts with the .sh extension?](https://askubuntu.com/q/503127). – pjh Feb 14 '23 at 14:44
  • 1
    'eval' is a common misspelling of 'evil'. If eval is the answer, surely you are asking the wrong question. See http://mywiki.wooledge.org/BashFAQ/048 – Gilles Quénot Feb 14 '23 at 15:38
  • Assigning the command-line pipeline to a variable in the script is very bad. It would be better to simply chose to execute "eval $1". Otherwise, any escaped quotations would be removed and change the interpretation of the pipeline. – Eric Marceau Feb 14 '23 at 21:07

0 Answers0