0

Following codes

echo 'input text : '
read -a names
for((i=0;i<${#names[@]};i++))
do
    name="${names[$i]}"
    echo "given input is"
    echo ${name}
    test="test1"
    color="${colors[$i]}"
    shape="${shapes[$i]}"
    if [ $name=$test ]
    then
      echo '1'
    elif [ $name="test2" ]
    then
      echo '2'
    else
      echo '3'
    fi
    echo "test done"
done

always give 1

✦2 ❯ sh ./test.sh input text : test1 given input is test1 1 test done

contradictory to the expectation. What would be correct syntax?

Tom Newton
  • 79
  • 1
  • 6
  • 1
    The relevance of the main duplicate question is made clear if you know that `[` is the same as the command `test`. – Kusalananda Dec 07 '22 at 14:08

0 Answers0