Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common parameters of the read command in shell

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what are the common parameters of the read command in shell, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

We know that there are two ways to receive incoming parameters in Shell. One is to pass parameters through a script, and the other is to receive incoming parameters through read. A simple example of passing parameters through a script is as follows:

# passed by script, where $0 refers to the script name, $1 is the first parameter, and $2 is the second parameter [root@host ~] #. / script.sh 1 2Total = 3 [root@host ~] # vim script function add () {total=$ (expr $1 + $2) echo-e "Total = $total"} add $1 $2

To receive the incoming parameters through read, let's first look at the basic format of read:

Read [- rs] [- an ARRAY] [- d delim] [- n nchars] [- N nchars] [- p prompt] [- t timeout] [var1 var2 var3.]

[root@host ~] # / script.sh Enter Password:The password your input is: Test@1234\ [root@host ~] # vim script.shemaking bind Bash read-N10-T30-r-s-d $- p "Enter Password:" passwordecho-e "\ nThe password your input is:$password"

-p prompt statement, followed by input prompt information, here is' Enter Password:'

The number of-n parameters, sometimes it is necessary to limit the password length, or other input length restrictions, such as [Ymax N], enter only one digit,-N1

-s screen echo, the input is not displayed on the screen, and is generally used for password input

-t wait time. Set here for 30 seconds. If it is not entered within 30 seconds or the input is incomplete, it will be terminated.

-d input limit, here is $, input to $, natural termination of input

-r masks the translation function of the special character\, and then treats it as an ordinary character.

From the above example, it basically includes most of the commonly used functions above, especially the parameters such as-pmam talk nm m et al., you can learn the command read very well.

These are all the contents of the article "what are the common parameters of the read command in shell?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report