Monday, January 4, 2016

Shell (8): User inputs.........

The command 'read' is a shell builtin.  It reads from stdin and assigns it to  a variable.
#Asks for input, then prints it
echo -n "Enter your name and press [ENTER]: "
read user_name
echo "Your name is: $user_name"
#Code asks user name; reads and stores the user information in a variable
echo Hello, who am I talking to?
read user_name
echo "Good Morning, $user_name!"

#Code asks user name and passwords and furnishes the login information.
read -p 'Username: ' user_var
read -sp 'Password: ' pass_var
echo "Hi $user_var, here is your login details: "

#Code asks the user about two of their favorite flowers
echo "Name two of your favorite flowers:"
read flower1 flower2
echo Your first favorite flower is: $flower1
echo Your second favorite flower is: $flower

No comments:

Post a Comment