Hey ,
i have this script and i have these loops so it can find a match between 2 arrays :
ARRAY_1=(one two three)
ARRAY_2=(A B C)
VAR='B'
for NUMBERS in "${ARRAY_1[@]}"
do
for LETTERS in "${ARRAY_2[@]}"
do
if [[ $VAR == *"$LETTERS"* ]];then
VAR='LETTERS'
break
fi
if [[ $VAR == *"$NUMBERS "* ]];then
VAR='NUMBERS'
break
else
VAR='DEFAULT'
fi
done
done
echo "$VAR"
the thing is that the loops dont break!
after it fines a match just keep looping and gets to default:
+ ARRAY_1=(one two three)
+ ARRAY_2=(A B C)
+ VAR=B
+ for NUMBERS in '"${ARRAY_1[@]}"'
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ B == *\A* ]]
+ [[ B == *\o\n\e* ]]
+ VAR=DEFAULT
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ DEFAULT == *\B* ]]
+ [[ DEFAULT == *\o\n\e* ]]
+ VAR=DEFAULT
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ DEFAULT == *\C* ]]
+ [[ DEFAULT == *\o\n\e* ]]
+ VAR=DEFAULT
+ for NUMBERS in '"${ARRAY_1[@]}"'
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ DEFAULT == *\A* ]]
+ VAR=LETTERS
+ break
+ for NUMBERS in '"${ARRAY_1[@]}"'
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ LETTERS == *\A* ]]
+ [[ LETTERS == *\t\h\r\e\e* ]]
+ VAR=DEFAULT
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ DEFAULT == *\B* ]]
+ [[ DEFAULT == *\t\h\r\e\e* ]]
+ VAR=DEFAULT
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ DEFAULT == *\C* ]]
+ [[ DEFAULT == *\t\h\r\e\e* ]]
+ VAR=DEFAULT
+ echo DEFAULT
DEFAULT
why ?!
i want it to work this way :
+ for NUMBERS in '"${ARRAY_1[@]}"'
+ for LETTERS in '"${ARRAY_2[@]}"'
+ [[ B == *\A* ]]
+ [[ B == *\o\n\e* ]]
+ [[ B == *\B ]]
+ [[ B == *\T\W\O* ]]
+ [[ B == *\C* ]]
+ [[ B == *\t\h\r\e\e* ]]