How to execute two commands stored in one bash variable

Let's say there is one bash variable

run1 = "date"

I need to execute dateon

$ {run1}

And it works as it prints the current time. But if I put two commands in a variable,

run2 = "date; echo foo"

I can’t execute the commands stored in the variable run2since it ${run2}complains

date ;: command not found

+5
source share
2 answers

Try:

eval ${run2}

This should help.

+5
source

Give it a try eval "${run2}". This will interpret the variable as a sequence of commands to run.

+2
source

All Articles