Does bash support word boundary regular expressions?

前端 未结 8 1648
面向向阳花
面向向阳花 2020-12-01 05:30

I am trying to match on the presence of a word in a list before adding that word again (to avoid duplicates). I am using bash 4.2.24 and am trying the below:



        
8条回答
  •  执念已碎
    2020-12-01 05:54

    You can use grep, which is more portable than bash's regexp like this:

    if echo $foo | grep -q '\'; then 
        echo "MATCH"; 
    else 
        echo "NO MATCH"; 
    fi
    

提交回复
热议问题