Bash Script接受多个提示

时间:2014-05-05 06:12:36

标签: bash shell githooks

我尝试创建一个 post-checkout git hook并拥有一个将运行composer updatephp artisan migrate:refresh的bash脚本,因为我'我刚刚开始使用bash脚本我无法弄清楚为什么我的脚本没有执行“运行迁移”#39;一部分?

#!/bin/bash
exec < /dev/tty

while true; do
    read -p "Run Composer Update[Y/n]: " yn
    case $yn in
        [Yy]* ) composer update; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac    
done
while true; do
    read -p "Run Migrations[Y/n]: " yn
    case $yn in
        [Yy]* ) php artisan migrate:refresh; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac    
done

1 个答案:

答案 0 :(得分:1)

在“否”选项中使用break代替exit

#!/bin/bash
exec < /dev/tty

while true; do
    read -p "Run Composer Update[Y/n]: " yn
    case $yn in
        [Yy]* ) composer update; break;;
        [Nn]* ) break;;
        * ) echo "Please answer yes or no.";;
    esac    
done
while true; do
    read -p "Run Migrations[Y/n]: " yn
    case $yn in
        [Yy]* ) php artisan migrate:refresh; break;;
        [Nn]* ) break;;
        * ) echo "Please answer yes or no.";;
    esac    
done