How to store a command in a variable in a shell script?

前端 未结 8 1008
长情又很酷
长情又很酷 2020-11-22 07:35

I would like to store a command to use at a later period in a variable (not the output of the command, but the command itself)

I have a simple script as follows:

8条回答
  •  攒了一身酷
    2020-11-22 08:28

    For bash, store your command like this:

    command="ls | grep -c '^'"
    

    Run your command like this:

    echo $command | bash
    

提交回复
热议问题