简体   繁体   中英

how to execute two commands stored in one bash variable

Let's say there is one bash variable

run1="date"

I need to execute date by

${run1}

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

run2="date; echo foo"

I can't execute the commands stored in variable run2 , since ${run2} complains

date;: command not found

Try:

eval ${run2}

This should help.

Try eval "${run2}" . That will interpret the variable as a sequence of commands to be run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM