Abhijeet Pandey
Abhijeet Pandey

Reputation: 1

Unix Shell Scripting ifelse error

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

Upvotes: 0

Views: 100

Answers (1)

pacholik
pacholik

Reputation: 8972

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

Upvotes: 1

Related Questions