


shell--standard input and output (read&echo)
Input read:
Purpose:
Read a line from the standard input, or read a line from the file descriptor FD (file descriptor), and It is divided into fields.
Usage:
read [-ers] [-a array] [-d delimiter] [-i buffer text] [ -n number of characters read] [-N number of characters read] [-p prompt] [-t timeout] [-u file descriptor] [name...]
Commonly used options:
-a:(arrary) Divide the read characters into words and store them in arrays (starting from 0)
#!/bin/ - ${variable[ ${variable[ ${variable[ ${variable[]}
<strong>运行效果:<br></strong>
Place the words into the array according to the segmentation, and the index starts from 0<br>34 ew qr34 3qr wer er qw<br>The first one:<br>34<br>The second one:<br>ew<br>The third one Number one: <br>qr34<br> Number four: <br>3qr
-n: Receive the specified number of characters. When the number of characters received is reached, Exit the input state immediately
源码:
#- -n ${num}
<strong>运行效果:<br></strong>
-n read accepts 10 characters<br>sgfgsngfdf<br>The 10 characters received are: sgfgsngfdf
<br>-p: Allows you to specify a prompt directly after the read command and assign values to multiple variables
源码:
-p $num3
<strong>运行效果:<br></strong>
使用-p参数完成多个变量赋值: 请输入三个数字或字符:(用空格隔开)23 34 345 num1=23num2=34num3=345
<br>
<br> -r :Does not allow backslashes to escape any characters
<br> -s:Do not display the data entered by read on the screen
源码:
#- -p - ${password}
<strong>运行效果:<br></strong>
- The input of s read is not displayed on the screen: <br>password:<br>password is 3432 rq erewr w
<br> -t : The number of seconds the read command waits for input. When the timer expires, it returns a non-zero status and exits waiting for input.
源码:
#- -t ${num}
<strong>运行效果:<br></strong>
Will wait for two seconds of input. After the timeout, it will exit the waiting; return a non-0 value
<br> -u: Read from file descriptor FD (file descriptor).
Supplementary content: File descriptor FDThe file descriptor is a non-negative integer in form. In fact, it is an index value pointing to the record table of files opened by the process maintained by the kernel for each process. When a program opens an existing file or creates a new file, the kernel returns a file descriptor to the process. In programming, some low-level programming often revolves around file descriptors. However, the concept of file descriptors is often only applicable to operating systems such as UNIX and Linux.By convention, the file descriptor of standard input is 0, standard output is 1, and standard error is 2. Although this convention is not a feature of the Unix kernel, because some shells and many applications use this convention, many applications will not work if the kernel does not follow this convention.
Example of reading from a file:
<br>
test. |
<br>运行效果:
read接受文本作为输入 接收的文本字符是:#------------------------------------------ 接收的文本字符是:#------------------------------------------ 接收的文本字符是:# read接受文本作为输入 接收的文本字符是:echo " read接受文本作为输入" 接收的文本字符是:cat test.sh | while read line 接收的文本字符是:do 接收的文本字符是:echo 接收的文本字符是:echo "接收的文本字符是:"${line} 接收的文本字符是:done
The above is the detailed content of shell--standard input and output (read&echo). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to delete Xiaohongshu notes? Notes can be edited in the Xiaohongshu APP. Most users don’t know how to delete Xiaohongshu notes. Next, the editor brings users pictures and texts on how to delete Xiaohongshu notes. Tutorial, interested users come and take a look! Xiaohongshu usage tutorial How to delete Xiaohongshu notes 1. First open the Xiaohongshu APP and enter the main page, select [Me] in the lower right corner to enter the special area; 2. Then in the My area, click on the note page shown in the picture below , select the note you want to delete; 3. Enter the note page, click [three dots] in the upper right corner; 4. Finally, the function bar will expand at the bottom, click [Delete] to complete.

<p>Customizing your operating system is a great way to make your daily life more enjoyable. You can change the user interface, apply custom themes, add widgets, and more. So today we will show you how to install ClassicShell on Windows 11. </p><p>This program has been around for a long time and allows you to modify the operating system. Volunteers have now started running the organization, which disbanded in 2017. The new project is called OpenShell and is currently available on Github for those interested. </p>&a

Notes deleted from Xiaohongshu cannot be recovered. As a knowledge sharing and shopping platform, Xiaohongshu provides users with the function of recording notes and collecting useful information. According to Xiaohongshu’s official statement, deleted notes cannot be recovered. The Xiaohongshu platform does not provide a dedicated note recovery function. This means that once a note is deleted in Xiaohongshu, whether it is accidentally deleted or for other reasons, it is generally impossible to retrieve the deleted content from the platform. If you encounter special circumstances, you can try to contact Xiaohongshu’s customer service team to see if they can help solve the problem.

Open shell not running on Windows 11 is not a new problem and has been plaguing users since the advent of this new operating system. The cause of the Open-Shell Windows 11 not working issue is not specific. It can be caused by unexpected errors in programs, the presence of viruses or malware, or corrupted system files. For those who don’t know, Open-Shell is the replacement for Classic Shell, which was discontinued in 2017. You can check out our tutorial on how to install Classic Shell on Windows 11. How to replace Windows 11 Start menu

Do you see this error message "Add-AppxPackage: Deployment failed with HRESULT: 0x80073D02, The package cannot be installed because the resource it modifies is currently in use. Error 0x80073D02..." in PowerShell when you run the script? As the error message states, this does occur when the user attempts to re-register one or all WindowsShellExperienceHost applications while the previous process is running. We've got some simple solutions to fix this problem quickly. Fix 1 – Terminate the experience host process You must terminate before executing the powershell command

Windows Subsystem for Linux The first option is to use Windows Subsystem for Linux or WSL, which is a compatibility layer for running Linux binary executables natively on Windows systems. It works for most scenarios and allows you to run shell scripts in Windows 11/10. WSL is not automatically available, so you must enable it through your Windows device's developer settings. You can do this by going to Settings > Update & Security > For Developers. Switch to developer mode and confirm the prompt by selecting Yes. Next, look for W
![Explorer.exe does not start on system startup [Fix]](https://img.php.cn/upload/article/000/887/227/168575230155539.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Nowadays, many Windows users start encountering severe Windows system problems. The problem is that Explorer.exe cannot start after the system is loaded, and users cannot open files or folders. Although, Windows users can open Windows Explorer manually using Command Prompt in some cases and this must be done every time the system restarts or after system startup. This can be problematic and is due to the following factors mentioned below. Corrupted system files. Enable fast startup settings. Outdated or problematic display drivers. Changes were made to some services in the system. Modified registry file. Keeping all the above factors in mind, we have come up with some that will surely help the users

Link AppleNotes on iPhone using the Add Link feature. Notes: You can only create links between Apple Notes on iPhone if you have iOS17 installed. Open the Notes app on your iPhone. Now, open the note where you want to add the link. You can also choose to create a new note. Click anywhere on the screen. This will show you a menu. Click the arrow on the right to see the "Add link" option. click it. Now you can type the name of the note or the web page URL. Then, click Done in the upper right corner and the added link will appear in the note. If you want to add a link to a word, just double-click the word to select it, select "Add Link" and press
