How can I write a shell script that will do a case-insensitive substring match of command output?
Case-insensitive substring search in a shell script
shell script;shell;string
First here's a simple example script that doesn't ignore case:#!/bin/bashif [ $(echo hello) == hello ]; then    echo it worksfiTry changing the string hello on the right, and it should no longer echo it works. Try replacing echo hello with a command of your choosing. If you want to ignore case, and neither string contains a line break, then you could use grep:#!/bin/bashif echo Hello | grep -iqF hello; then    echo it worksfiThe key here is that you are piping a command output to grep. The if statement tests the exit status of the rightmost command in a pipeline - in this case grep. Grep exits with success if and only if it finds a match.The -i option of grep says to ignore case.The -q option says to not emit output and exit after the first match.The -F option says to treat the argument as a string rather than a regular expression.Note that the first example uses [ expression ] which allows direct comparisons and various useful operators. The second form just execs commands and tests their exit status.