Question

I'm trying to create a post-checkout git hook and have the a bash script that will run composer update and php artisan migrate:refresh, Since I'm just beginning with bash scripting I can't figure out why my script doesn't execute the 'Run Migrations' part?

#!/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
Was it helpful?

Solution

Use break instead of exit in the "No" option

#!/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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top