shell - check whether elements are present in list or not bash -


this question has answer here:

  : ${models:=foo bar foobar baz}   : ${special_list:=station_tracks user_features}     model in $models;          echo $model     if # model in special list; # how test this?        #          continue      fi done 

so, how test whether variable model in special_list or not?

perl has smartmatch operator ~~. has been noted, bash , not awk have equivalent, use grep workaround. before continue, if going use bash array, use bash array. syntax going break horribly once beyond simple example, space, gets involved:

models=(foo bar foobar baz) special_list=(station_tracks user_features) model in "${models[@]}"   echo "$model"   if printf '%s\0' "${special_list[@]}" | grep -fqxz "$model"       continue   fi done 

if prefer can use equivalent long options:

--fixed-strings --quiet --line-regexp --null-data 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -