Linux Shell Scripting TutorialIntroduction 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 files
Reading data from user in linux shell scriptingYou 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.
We can read the data from standard input and initialize multiple variables as well
echo “Please enter your name “ read your_name echo “Your name is : $your_name”
When we do not specify the name of variable, read command will assign the value to special variable “REPLY”
read name age city echo “name = $name age = $age city = $city”
To prevent new lines, you can use “-en” option with echo command.
read echo “You entered $REPLY”
Using different field separator
echo -en “Please enter your name “ read your_name echo “Your name is : $your_name”
[email protected] 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”
Complex problems, Simple Solutions