burim:bash:udemy:read
Read User Input Example
#! /bin/bash
echo "Enter name : " read name echo "Enterd name : $name"
- Multiple inputs
echo "Enter names : " read name1 name2 name3 echo "Names : $name1 , $name2, $name3"
- Two commonly used options however are
- -p which allows you to specify a prompt
- -s which makes the input silent.
read -p 'username : ' user_var read -sp 'password : ' pass_var echo echo "username : $user_var" echo "password : $pass_var"
- -a makes read command to read into an array
echo "Enter name : "
read -a names
echo "Names : ${names[0]}, ${names[1]}"
- read command will now store the reply into the default build-in variable $REPLY
echo "Enter name : " read echo "Name : $REPLY"
- default variable
echo "Enter name: " read echo "Name : $REPLY"
burim/bash/udemy/read.txt · Last modified: 2019/09/05 09:25 by burim
