umop
umop

Reputation: 2192

Interpreting command substitution from a variable in bash

For the following value of FOO:

$ FOO='echo `echo hello`'
$ $FOO
`echo hello`

how can I get the expected output:

hello

Basically, how can I interpret a command substitution in the contents of a variable?

Upvotes: 1

Views: 930

Answers (2)

Debaditya
Debaditya

Reputation: 2497

Try this

$ FOO="echo `echo hello`"
$ $FOO 

Just replace single quotes with double quotes.

Upvotes: -2

chepner
chepner

Reputation: 531165

Answering the question as given,

eval $FOO

but you're probably going about your real problem the wrong way.

Upvotes: 5

Related Questions