条件语句被跳过

时间:2018-11-11 07:43:37

标签: bash

我是scripting的新手。如何更正此bash脚本。对于所有值,它给了我“其他”条件-“错误值”

     #!/bin/bash
     read -p "First Name: " $first
     read -p "Last Name: " $last
     read -p "profession 1 for software and 2 for hardware (1/2): " $pro
     echo $first
     if [ "$pro" == "1" ];then
        echo $first
        echo $last
     elif [ "$pro" == "2" ];then
     echo $first
     echo $last
     echo $pro
     else
        echo "wrong value!"
    fi

1 个答案:

答案 0 :(得分:1)

您需要更改...

read -p "First Name: " $first
read -p "Last Name: " $last
read -p "profession 1 for software and 2 for hardware (1/2): " $pro

…到…

read -p "First Name: " first
read -p "Last Name: " last
read -p "profession 1 for software and 2 for hardware (1/2): " pro

请注意,在$firstlast上缺少pro。在shell中,为变量分配值时,请勿在变量上使用$