Saturday, March 4, 2017

Shell Scripting Tutorial for Beginners 3 - Read User Input

#! /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 "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 : "
echo "Name : $REPLY"
IT Certification Category (English)640x480

Partner Sites

Top Online Courses From ProgrammingKnowledge

Python Course
Java Course
Bash Course
Linux Course
C Course
C++ Course
PHP Course
Android Course
C# Course
JavaFx Course
NodeJs Course
Jenkins Course
Scala Course
Bootstrap Course
MongoDB Course
QT C++ GUI Course