字符串包含
[[ $var1 = $var2 ]] && echo "1" || echo "2"
[[ ${var1/$var2/} != $var1 ]] && echo "1" || echo "2"
echo $var1 | grep $var2 1>/dev/null; echo $?
[[ $var1 =~ $var2 ]] && echo "1" || echo "2"
去除空格
echo $str 缺点:中间多个空格会变成一个
echo $str | sed 's/^[ \t]//g' | sed 's/[ \t]$//g'
echo "$str" | grep -o "[^ ]+( +[^ ]+)*"