Skip to main content
4 of 7
Updated title to reflect text in the question.
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

How to obtain grep exit status into a variable

I started learning Bash a couple of days ago.

I'm trying to obtain an exit status of grep expression into a variable like this:

check=grep -ci 'text' file.sh 

and the output that I got is

No command '-ic' found 

Should I do it with a pipe command?

omri gilhar
  • 343
  • 1
  • 2
  • 5