Search code examples
linuxbashshellglob

why wild card not working in if clause bash


Hi below is my code in shell scripting


for i in "${status_array[@]}"
do
        if [[ $i == "*start*"  ]]; then
                echo "$i"
                echo "${service_array[$count]}  $i "
        fi

        count=`expr $count + 1`
        isStarted=""
done

for j in "${status_array[@]}"
do
        echo "$j"
done


In this script for below loop for j , $j shows few values as stop.waiting and few as start/running. but for above loop control comes to the if clause block. and also here $i shows every value as start/running, so why this happen in that case.


Solution

  • You should change "*start*" to *"start"*. If you place glob patterns around quotes, it would be matched in literal form.