Assign grep count to variable

后端 未结 3 1958
长发绾君心
长发绾君心 2021-02-05 02:23

How to assign the result of

grep -c \"some text\" /tmp/somePath

into variable so I can echo it.

#!/bin/bash
some_var = grep -c         


        
3条回答
  •  耶瑟儿~
    2021-02-05 02:47

    To assign the output of a command, use var=$(cmd) (as shellcheck automatically tells you if you paste your script there).

    #!/bin/bash
    some_var=$(grep -c "some text" /tmp/somePath)
    echo "var value is: ${some_var}"
    

提交回复
热议问题