Bash: Check if a Variable Contains a Specific String
You can use the '[[` operator in Bash to determine if a variable contains a specific string. Here's the syntax:
if [[ $variable == *cus* ]]; then
echo 'Variable contains 'cus''
else
echo 'Variable does not contain 'cus''
fi
In this example, '$variable' is the variable you want to check, and 'cus' is the pattern to match. If the variable contains the string 'cus', it will print 'Variable contains 'cus'', otherwise, it will print 'Variable does not contain 'cus'.
原文地址: https://www.cveoy.top/t/topic/qdAc 著作权归作者所有。请勿转载和采集!