In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Do not know how to use linux's read to read a single row of data? In fact, it is not difficult to solve this problem. Let the editor take you to learn how to solve it. I hope you will gain a lot after reading this article.
The Linux read command is used to read values from standard input. Read internal commands are used to read a single line of data from standard input. This command can be used to read keyboard input and to read a line of data in a file when redirecting is used.
Syntax format: read [parameters]
Common parameters:
-an is followed by a variable, which is considered to be an array and assigned to it. By default, a space is used as a separator-- d is followed by a marker, but only the first character after it is useful. as a sign of the end-p is followed by a prompt, that is, to print a prompt before typing-e can use the command completion function when typing-n followed by a number Defines the length of the input text-- r mask\, if not,\ as an escape character, or a normal character if possible-- s quiet mode, which is no longer displayed on the screen when entering characters-- t followed by seconds, defines the waiting time for input characters-- u followed by fd, read from the file descriptor, which can be newly opened by exec.
Reference example
Simple read:
#! / bin/bash echo "enter the website name:" read file echo "the website name you entered is $file" exit 0
Allows you to specify a prompt directly on the read command line:
#! / bin/bashread-p "enter the website name:" fileecho "the website name you entered is $file" exit 0
Specifies the number of seconds the read command waits for input, and when the time expires, the read command returns a non-zero exit status:
#! / bin/bashif read-t 5-p "enter the site name:" filethen echo "the site name you entered is $file" else echo "\ nSorry, your input timed out." Fiexit 0
Sets the number of characters entered by the read command. When the number of characters entered reaches a predetermined number, it automatically exits and assigns the entered data to the variable:
#! / bin/bashread-N1-p "Do you want to continue [Ygamma N]?" Answercase $answer inY | y) echo "fine, continue"; N | n) echo "ok,good bye";; *) echo "error choice";; esacexit 0
Make the data entered in the read command not displayed on the command terminal:
#! / bin/bashread-s-p "Please enter your password:" passecho "\ nThe password you entered is $pass" exit 0 Thank you for reading this article carefully. I hope it is helpful for the editor to share the use of linux's read to read single-line data. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.