Shell Script Raiders (learning note)--1.12 Read basics

Source: Internet
Author: User

To interact with Linux, the script gets keyboard input results that are essential, and read can read the keyboard input characters.

1. Restricting input characters

For example, after you enter 5 characters, you end up with 5 characters entered into the variable. In other words, rely on the number of characters entered as the end flag.

Read-n num var: the input num characters are stored in variable var.

[[email protected] tmp]# Read-n 5 var

12345[[email protected] tmp]# echo $var ? Input 12345 A total of 5 characters

12345

2. Do not echo the input characters

For example, when entering a password, do not echo the password entered.

read-s var: the input character is stored in var. After entering, press ENTER to finish.

[email protected] tmp]# read-s var ? Enter 987654 here

[Email protected] tmp]# echo $var

987654

3. Give the input hint

Use the-P option.

[Email protected] tmp]# read-p "Please input your name:" var

Please input your name:myname

[Email protected] tmp]# echo $var

MyName

4. Give the input time limit

Automatically end without input in a few seconds, or enter a part to the limit time to end automatically, the input initialization variable is not completed, that is, discard the result and let the variable be called the Unassigned State.

[Email protected] tmp]# read-t 5-p "Please input your name in three seconds:" Var

5. Give the end delimiter

The character before the input delimiter is stored in the variable.

[Email protected] tmp]# read-d "," var

Jinse,[[email protected] tmp]# echo $var

Jinse

Shell Script Raiders (learning note)--1.12 Read basics

Related Article

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.