linux 带有条件(if、case)的Bash脚本工作不正确

sczxawaw  于 2023-08-03  发布在  Linux
关注(0)|答案(1)|浏览(112)

我试着这样创建bash脚本:

#!/bin/bash

echo "Where are you now?"
read $city

if [[ $city == "Kyiv" ]] && [[ $city == "Berlin" ]] && [[$city == "California"]];
then
        case $city in
        Kyiv)
        echo "Ukraine";;
        Berlin)
        echo "Germany";;
        California)
        echo "USA"
  esac

else
        echo  "$city Its not the city"
fi

字符串
并始终输出:
第一个月
我检查了很多文档,但找不到问题。
还有,
尝试使用不带“case”的条件语句:

#!/bin/bash

echo "Where are you now?"
read $city
if [[ $city == "Kyiv" ]]
then
        echo "Ukraine"
elif [[ $city == "Berlin" ]]
then
        echo "Germany"
elif [[ $city == "California" ]]
then
        echo "USA"
else
        echo " $city Its not the city"
fi


但输出相同:
It’s not the city

vltsax25

vltsax251#

#!/bin/bash

echo "Where are you now?"

read -r city

 if [[ $city == "Kyiv" ]]  || [[ $city == "Berlin" ]] || [[ $city == "California" ]];

 then

 case $city in

 Kyiv)
 echo "Ukraine";;

 esac

 case $city in

 Berlin)

 echo "Germany";;

 esac

 case $city in
 California) 
 echo "USA";;
 *)
 esac
 else
 echo " $city It's not the city "

fi

字符串

相关问题