0
confirm() {
local YES="Y"
local NO="N"
local CONT="C"
    while : 
    do
    echo –n "(Y)es/(N)o/(C)ontinue? {Y] "
        read answer
        answer=`echo "$answer" | tr '[a-z]' '[A-Z]'`
        echo "$answer"
        if [ "$answer"=$YES ]
        then
                echo "YES"
                return 0
        elif ["$answer"="$CONT" ]
        then
                echo "skip skip skip"
                return 2
        elif [ "$answer"="$NO" ]
        then
                echo "NO"
                return 1
        fi
    done
}

The ouput always echo YES and return 0, no matter what the input is.

1
  • how should i fix it
    – furqon2710
    Apr 5, 2020 at 17:17

1 Answer 1

5

You are missing mandatory whitespaces around the operator, i.e. = in your case:

if [ "$answer" = "$YES" ]

This concerns every condition.

1
  • bring out the popcorn
    – user986805
    Apr 5, 2020 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.