Linux 如何让用户在通过bash脚本执行一系列任务时更正错误?

Linux 如何让用户在通过bash脚本执行一系列任务时更正错误?,linux,bash,shell,Linux,Bash,Shell,我想自动化一系列任务任务任务1、任务2、任务3、任务4、任务5- status = Task_1 if (status == FALSE) *give option for user to rectify the problem, once done, proceed to Task_2* status = Task_2 if (status == FALSE) *give option for user to rectify the problem, once done, proc

我想自动化一系列任务任务任务1、任务2、任务3、任务4、任务5-

status = Task_1
if (status == FALSE)
   *give option for user to rectify the problem, once done, proceed to Task_2*
status = Task_2
if (status == FALSE)
   *give option for user to rectify the problem, once done, proceed to Task_3*
status = Task_3
if (status == FALSE)
   *give option for user to rectify the problem, once done, proceed to Task_4*
status = Task_4
if (status == FALSE)
   *give option for user to rectify the problem, once done, proceed to Task_5*
status = Task_5
我怎样才能达到目标- “为用户提供纠正问题的选项,完成后,继续执行任务\u X” ?

编辑:

我正在研究一种类似于的功能-

  • 执行git pull--rebase
  • 如果存在合并问题,则会通知用户并让他们采取行动
  • 一旦用户纠正了错误,他们就可以执行git-rebase——继续执行原来的rebase过程

  • 通常,命令具有退出状态。如果任务编写良好,则如果任务失败,退出状态应为非零,如果任务成功,退出状态应为零。因此,在bash中,您可以编写如下内容:

    #!/bin/bash
    if Task_1 ; then
        echo 'Task_1 succeeded'
    else
        #give option to rectify the problem
    fi
    
    对于剩余的任务,依此类推

    您还可以使用上一个任务的退出代码,
    $?
    ,如中所示

    Task_1
    if [ $? != 0 ] ; then
        echo "Despair! Task_1 has failed"
        # allow the user to do some reparations
    fi
    
    让用户选择修复在很大程度上取决于修复的方式以及您的环境

    例如,您可以显示具有固定操作的菜单,如:

    echo "a for abandon hope, b for be despaired"
    read line
    case "$line" in
    ("a")
        # actions for abandoning hope
        ;;
    ("b")
        # actions for being despaired
        ;;
    ("*")
        echo "Unknown action; continuing without doing anything."
        ;;
    esac
    
    或者,有时您可以只启动一个xterm:

    echo "Close terminal when the repair is finished"
    xterm
    

    (为这些令人沮丧的示例感到抱歉)

    是否要暂停脚本,向用户显示消息,然后让他们按键继续?发布的代码不是Bash。使用
    man-P“less+/component\commands”bash
    获取有关bash复合命令(包括if语句)的信息。@that otherguy我正在查看一个类似于-1的功能。执行git pull--rebase,2。如果存在合并问题,则会通知用户并让他们采取行动。3.一旦用户纠正了错误,他们就可以执行git-rebase——继续执行原来的rebase过程。