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

前端 未结 8 1083
长情又很酷
长情又很酷 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:25

    #!/bin/bash
    #Note: this script works only when u use Bash. So, don't remove the first line.
    
    TUNECOUNT=$(ifconfig |grep -c -o tune0) #Some command with "Grep".
    echo $TUNECOUNT                         #This will return 0 
                                        #if you don't have tune0 interface.
                                        #Or count of installed tune0 interfaces.
    

提交回复
热议问题