如何检查字符串在bash shell中是否有空格

可以在bash中使用正则表达式:

string="a b '' c '' d"
if [[ "$string" =~ \ |\' ]]    #  slightly more readable: if [[ "$string" =~ ( |\') ]]
then
   echo "Matches"
else
   echo "No matches"
fi
posted @ 2021-05-17 10:47  技术颜良  阅读(1052)  评论(0编辑  收藏  举报