Linux Shell Scripting Tutorial
Introduction Tools required for shell scripting First shell script Interacting with user Operators Special characters in BASH scripting Variables in Linux BASH scripting Arrays Integer operations floating point operations String manipulation in shell scripting Parameter substitution Command Substitution Conditional statements Looping statements Passing parameters exit status of the script Functions Sourcing filesReading data from user in linux shell scripting
You can take input from the user using read command. Below program will prompt you to enter your name and once you enter your name, it will be printed back on to the screen.
echo “Please enter your name “
read your_name
echo “Your name is : $your_name”
We can read the data from standard input and initialize multiple variables as well
read name age city
echo “name = $name age = $age city = $city”
When we do not specify the name of variable, read command will assign the value to special variable “REPLY”
read
echo “You entered $REPLY”
To prevent new lines, you can use “-en” option with echo command.
echo -en “Please enter your name “
read your_name
echo “Your name is : $your_name”
Using different field separator
IFS=@
echo “Enter the 2 values delimited by @ and then hit enter key”
read a b
echo “Value of a is $a”
echo “Value of b is $b”
Web development and Automation testing
solutions delivered!!