如果条件在bash中不正常工作

如果条件在bash中不正常工作,bash,conditional-statements,Bash,Conditional Statements,代码 运行sh后,设置参数$Setup视图为“n”,但条件仍然会启动部分运行。哪里有错误的代码 谢谢。将其更改为: if [ $setup==="y" ] then echo "kurulum:"$setup exit full_dir=$full_dir"/public" else echo "Sub-Public folder is exist? [public,web]" read folder_ext

代码

运行sh后,设置参数$Setup视图为“n”,但条件仍然会启动部分运行。哪里有错误的代码

谢谢。

将其更改为:

if [ $setup==="y" ]
    then
        echo "kurulum:"$setup
        exit
        full_dir=$full_dir"/public"
    else
    echo "Sub-Public folder is exist? [public,web]"
        read folder_extend
        if [ $folder_extend ]
                then
                full_dir=$full_dir"/"$folder_extend
        fi
fi

它应该是一个单独的
=
,您需要在它周围留有空格。在大多数上下文中,如果变量包含空格,您也应该引用变量。

@Aybarscenegaver:如何填充$setup?在
if
测试中,
=
周围没有空格。
if [ "$setup" = "y" ]
    then
        echo "kurulum:"$setup
        exit
        full_dir=$full_dir"/public"
    else
    echo "Sub-Public folder is exist? [public,web]"
        read folder_extend
        if [ "$folder_extend" ]
                then
                full_dir=$full_dir"/"$folder_extend
        fi
fi