mardi 23 février 2016

bash evaluate if statement from string

I have a file which contains shell test statements.

I need to evaluate the expression. For example:

a="something"
fromfile='[ "$a" == "something" ]'

if `$fromfile`; then
  echo "true"
else
  echo "false"
fi

It always throws false. I tried with `` and eval, but still not works.

What is the solution?

Aucun commentaire:

Enregistrer un commentaire