mardi 27 décembre 2016

Bash - Check if array element starts with usr- [duplicate]

This question already has an answer here:

This is how my input looks like:

privatertid=[ "usr-11111", "usr-22222" ]

I am looping thru this treating it as an array and if the the string starts with usr-, I want to do more operations on it.

for i in $privatertid; do
  echo checking $i
  if [[ "$i" == usr-* ]]; then
    echo user:$i
  fi;
done

Control of the program never echoes user:usr-11111 or user:usr-22222.

Am i not comparing the "string starts with usr-" correctly?

Aucun commentaire:

Enregistrer un commentaire