shell 判断字符串中是否含有指定字符

new=sdd
ps=s
echo "$new" |grep -q "$ps"
if [ $? -eq 0 ]
then
echo "yes"
else
echo "no"
fi




判断某年某天是星期几?
year=1980
end_year=2010
day_2=10/22
week_2=Fri


while [ $year -lt $end_year ]
do
new=`date -d "$day_2 CST $year"`
echo "$new"
echo "$new" |grep -q "$week_2"
if [ $? -eq 0 ]
then      
      #  year=`expr $year + 1`
 echo "this year $year include $week_2"


    year=`expr $year + 1`
else
    #echo "this year $year include $week_2"
    year=`expr $year + 1`
fi  
done

你可能感兴趣的:(shell 判断字符串中是否含有指定字符)