0

Please help, This script gives following error while executing :

Then unexpected Str1 not found Str2 not found

#!/bin/ksh 

echo ">>Please press y or n :"
read Str

Str1="y"
Str2="n"
if[[$Str1 == $Str]];then
echo "You pressed Y."
elif[[$Str2 == $Str]]; then
echo "You pressed N."
else
echo "Error."
fi
2
  • Error 1 : Syntax error : 'then' unexpected Error 2 : 'Str1' Not found Error 3 : 'Str2' Not found Commented Dec 16, 2015 at 11:45
  • Use shellcheck.net - I really wish that I could find a decent duplicate for this common issue related to missing spaces around [. Commented Dec 16, 2015 at 12:05

1 Answer 1

1

You are missing whitespaces.

#!/bin/ksh 

echo ">>Please press y or n :"
read Str

Str1="y"
Str2="n"
if [[ $Str1 == $Str ]]; then
    echo "You pressed Y."
elif [[ $Str2 == $Str ]]; then
    echo "You pressed N."
else
    echo "Error."
fi
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.