Receive keyboard input in Linux

Source: Internet
Author: User

Read option variable name
-P "prompt message"
-t Specifies the wait time, without specifying it waits
-n Specifies the number of characters to be received, without specifying a limit
-S hidden input data, suitable for confidential information input

[Email protected] sh]# VI param_test3.sh
[email protected] sh]# cat param_test3.sh
#!/bin/bash

# Prompt the user to enter and wait 30 seconds and put the input result into the name variable
Read-t 30-p "Please input your name:" Name
Echo-e "\ n"
echo "Name is $name"

# Plus-S will be hidden when entering age
Read-s-T 30-p "Please input your Age:" Age
Echo-e "\ n"
echo "Age is $age"

#-N 1 means only one character is received
Read-n 1-t 30-p "Please input gender m/f:" Gender
Echo-e "\ n"
echo "Genger is $gender"

[Email protected] sh]# sh param_test3.sh
Please input Name:xiaol
Name is Xiaol
Please input your age:
Age is 12
Please input gender m/f: M
Genger is M
[Email protected] sh]#

Receive keyboard input in Linux

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.