Common read methods in Shell

Source: Internet
Author: User

Syntax of the common read command in Shell: [python] 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 will be assigned to variable1variable2: The second value entered by the user will be assigned to variable2. sh file, input: [python] #! /Bin/bash read-p "Enter your name:" name echo "Hi, $ name. Let us be friends! "Save and close the file. Enter [python] chmod + x greet in the command line. sh. /greet. sh output: [python] Enter your name: Tomcat Hi, Tomcat. let us be friends! The following is an example file used to display the domain name information entered by the user: [python] #! /Bin/bash read-p "Enter the Internet domain name (e.g. nixcraft.com):" domain_name whois $ domain_name time setting you can use the-t parameter to limit the user input time. For example, use the following command to set the user to enter the parameter in 10 seconds: [python] #! /Bin/bash read-t 10-p "Enter the Internet domain name (e.g. nixcraft.com):" domain_name whois $ domain_name Enter the password and use the-s parameter to display user input. Example: [python] #! /Bin/bash read-s-p "Enter Password:" my_password echo "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.