Document directory
- Syntax of the read command:
- Process Input
Original article: Linux Shell scripting tutorial V2.0
Syntax of the read command:
read -p "Prompt" variable1 variable2 variableN
-P "prompt": displays the prompt information (displayed in the same line as the user input)
Variable1: the first value entered by the user is assigned to variable1.
Variable2: The second value entered by the user is assigned to variable2.
Process the input and create a file named Greet. Sh. input:
#!/bin/bashread -p "Enter your name : " nameecho "Hi, $name. Let us be friends!"
Save and close the file, and enter:
chmod +x greet.sh./greet.sh
Output:
Enter your name : TomcatHi, Tomcat. Let us be friends!
The following is an example file used to display the domain name information entered by the user:
#!/bin/bashread -p "Enter the Internet domain name (e.g. nixcraft.com) : "domain_namewhois $domain_name
You can use the-t parameter to limit the user's input time. For example, use the following command to set the user's input parameters within 10 seconds:#!/bin/bashread -t 10 -p "Enter the Internet domain name (e.g. nixcraft.com) : "domain_namewhois $domain_name
Enter the password and use the-S parameter to disable user input. Example:#!/bin/bashread -s -p "Enter Password : " my_passwordechoecho "Your password - $my_password"