如何结束一个shell脚本?

如何结束一个shell脚本?

我正在 Linux 上编写一个脚本,我想添加一点额外的内容并询问用户是否要退出该程序,任何人都可以帮助我弄清楚如何做到这一点吗?

答案1

尝试这个:

read -p "Do you want to continue? (y/N) " ANS
    # if not, do something else, otherwise fall out the bottom
    [ "$ANS" = "y" -o "$ANS" = "Y" ] && {
            # commands here what to do if we stick around
            echo "OK, we will continue"
            # better put something else to do here or we'll fall out anyway.
            }

相关内容