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 "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
.
To assign the output of a command, use
var=$(cmd)
(as shellcheck automatically tells you if you paste your script there).Found the issue
Its the assignment, this will work:
While this won't work:
Thank you for your help! I will accept first helpful answer.
From
man bash
: