jeudi 26 octobre 2017

Error when running command inside variable with `if`

We've got a script running the last 2 commands. But it's failing..

$ if [ -d / ]; then echo a; else echo b; fi
a
$ bash -c 'if [ -d / ]; then echo a; else echo b; fi'
a
$ A="bash -c 'if [ -d / ]; then echo a; else echo b; fi'"
$ $A
[: -c: line 0: unexpected EOF while looking for matching `''
[: -c: line 1: syntax error: unexpected end of file

I really wonder why? Thanks!

Aucun commentaire:

Enregistrer un commentaire