bash script assign grep count to variable

How to assign the result of grep -c "some text" /tmp/somePath into variable so I can echo it. Thanks!

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

I also tried: some_var = 'grep -c \"some text\" /tmp/somePath'

But I keep getting: command not found

Thanks

Answers


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}"

Need Your Help

how to convert list of lists to a set in python so I can compare to other sets?

python list set

I have a list users_with_invites_ids_list, formed by loop where I append values to the list, in python that looks like this:

hello world python extension in c++ using boost?

c++ linux compiler-errors boost-python

Here's my simple first attempt at a python extension using boost. Can someone help me to understand what's causing the compilation error?