Search code examples
bashconfirm

How can I protect a terminal command with confirmation?


I have a makefile that will deploy my current django project to my live server. Is there a way to catch the terminal command "make sync_live" and request confirmation with something like

"Deploy Changes to Live? [Y,n]"

before it executes? Either in the makefile or in a bashrc file? I'm on Ubuntu 14.04. Thanks.


Solution

  • read -p "Deploy Changes to Live? " -n 1 -r
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        # Execute if condition passes
    fi