I have the following bash script:
set -ex
X="bash -c"
Y="ls -al"
I want to execute (notice the double quotes):
bash -c "ls -al"
The following does not work:
C=$X\ $Y
$C
This gives as output
+ X='bash -c'
+ Y='ls -al'
+ C='bash -c ls -al'
+ bash -c ls -al
There are no double quotes around ls -al
I tried this:
C=$X\ \"$Y\"
But that doesn't work:
+ X='bash -c'
+ Y='ls -al'
+ C='bash -c "ls -al"'
+ bash -c '"ls' '-al"'
How to correctly concatenate Y to X while keeping double quotes around Y?
echo $Z | sh
works. Oreval $Z
. – Jim L. Jun 27 '19 at 23:51