Common read methods in Shell

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.