Ever wanted a command that asks for confirmation before executing another command?
No? Well, me neither!
Here's a command that will ask for your confirmation before running the next command:
confirm() {
echo -n "Do you want to run $*? [N/y] "
read -N 1 REPLY
echo
if test "$REPLY" = "y" -o "$REPLY" = "Y"; then
"$@"
else
echo "Cancelled by user"
fi
}
It's also very easy to use:
root@root:~# confirm echo "Hello world!"
Do you want to run echo Hello world!? [N/y] y
Hello world!
Top comments (0)