Testing $?
is an anti-pattern.
if ./somecommand | grep -q 'string'; then
echo "matched"
fi
More Related Contents:
- Capturing Groups From a Grep RegEx
- How to get the part of a file after the first line that matches a regular expression
- How to process each output line in a loop?
- Colorized grep — viewing the entire file with highlighted matches
- How to check if a file contains a specific string using Bash
- Piping tail output though grep twice
- Waiting for background processes to finish before exiting script
- How to strip out all of the links of an HTML file in Bash or grep or batch and store them in a text file
- How to grep for case insensitive string in a file?
- What does 2>&1 mean here?
- How to reload .bashrc settings without logging out and back in again?
- How do I iterate over a range of numbers defined by variables in Bash?
- When do we need curly braces around shell variables?
- How can I pipe stderr, and not stdout?
- Bash command line and input limit
- How to assign the output of a Bash command to a variable? [duplicate]
- Using the RUN instruction in a Dockerfile with ‘source’ does not work
- Why start a shell command with a backslash?
- Open and write data to text file using Bash?
- bash set -e and i=0;let i++ do not agree
- Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?
- Why is “[[ 10 < 2 ]]" true when comparing numbers in bash? [duplicate]
- How to go to each directory and execute a command?
- Read a variable in bash with a default value
- Relative paths based on file location instead of current working directory [duplicate]
- Counting lines or enumerating line numbers so I can loop over them – why is this an anti-pattern?
- pipe stdout and stderr to two different processes in shell script?
- How can I convert tabs to spaces in every file of a directory?
- Use GNU find to show only the leaf directories
- Get the name of the caller script in bash script