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

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

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -