User Intraction in Shell Scripts
In some cases the script needs to intract with the user and accept inputs.
In shell scripts we use the read statement to take input from the user.
The read statement in Linux Shell Scripting
The Read Statement
Used to get input (data from user) from keyboard and store (data) to variable.
Syntax:
read variable1, variable2,...variableN
Lets write a shell script to ask the user his name and print it. While running this script it waits for the user input.
#Script to read your name from key-board echo "Enter your name:" read name echo "Hello $name, Welcome to the world of Linux!"
Result
Save the above file as your-name.sh
Run it as follows:
$ chmod 755 your-name.sh
$ ./your-name.sh
Enter your name: Tom
Hello Tom, Welcome to the world of Linux!
Related posts:
- Shell Scripting Introduction
- Shell Syntax
- Shell - Strings
- Shell - Variables
- Shell - User Intraction
- First Shell Script
- Shell - Arithmetics
- Shell - Case Statement
- Shell - Command Line Arguments
- Shell - For Loop
- Shell - While Loops
- Shell - IF Statements
- Shell - Input Output Redirections
- Shell - Pipes and Filters
- Shell - Process Management
Your IP address1 is: 172.18.0.2
Tutorials
Latest Updates
Follow us
- Tech-Tutorials twitter.com/techcuriosity