0

when I try to implement if statement in shell script, somehow I met this problem, what I want to do is when the input option is yes, prompt to ask users to enter longitude, latitude and width, if the input is not yes, then skip to end.

#!/bin/bash    
echo "Please enter keyword:"
read keyword
export keyword
echo "Do you want to search longitude and latitude? enter yes or no"
read option
if [[ $option=="yes" ]]; then
    echo "Please enter longitude:"
    read longitude
    export longitude
    echo "Please enter latitude:"
    read latitude
    export latitude
    echo "Please enter width:"
    read width
    export width
fi
ZHICHU ZHENG
  • 301
  • 2
  • 3
  • 8
  • 2
    spaces -> `if [[ $option == "yes" ]]; then` – anubhava Mar 17 '16 at 16:48
  • 2
    @ZhichuZheng, keep in mind that the shell parses code by splitting it into tokens separated by whitespace. Particularly, the expressions in `[[ double brackets ]]` act differently based on the number of white-space separated words. When given a single argument (like "$option==yes") `[[` returns true if the argument has non-zero length, which your expression always has, regardless of the value of $option. – glenn jackman Mar 17 '16 at 17:05

0 Answers0