how create simple shell script asks simple input user , runs command associated predefined choice, example
if "on" backup server elseif "off" delete backups elseif "grey" send backups endif
you can take input user via read , can use case ... esac block different things.
read takes argument, name of variable store it's value
read foo will take in vaue user , store in $foo.
to prompt user input need use echo.
echo "what favourite color?" read color finally, shell scripts support case operator. take form
case "value" in "choice) # stuff ;; esac putting together:
echo "which choice like? \c" read choice case "$choice" in on) # stuff ;; off) # different stuff ;; *) echo "$choice not valid choice" ;; esac
Comments
Post a Comment