Fli
10-25-2013, 09:17 PM
When we want to check some linux command output if contains some phrasse, or words, it can be done by adding the command output into variable like this:
varname=$(thecommandhere)
then we check if varname is equal to *example*:
[[ $varname == *example* ]] && echo "Found"
$ [[ $varname == *example* ]] && echo Found || echo Not found
Found
Maybe better way if the match is phrasse with spaces is adding this phrasse into its own variable, not directly into "If"
varname='My long string';
if [[ "$varname" == *My* ]];then
echo "It's there!";
fi
varname2=''m long"
if [[ "$varname" == *"$varname2"* ]]; then
echo "The '$varname' contains phrasse '$varname2'"
fi
varname=$(thecommandhere)
then we check if varname is equal to *example*:
[[ $varname == *example* ]] && echo "Found"
$ [[ $varname == *example* ]] && echo Found || echo Not found
Found
Maybe better way if the match is phrasse with spaces is adding this phrasse into its own variable, not directly into "If"
varname='My long string';
if [[ "$varname" == *My* ]];then
echo "It's there!";
fi
varname2=''m long"
if [[ "$varname" == *"$varname2"* ]]; then
echo "The '$varname' contains phrasse '$varname2'"
fi