Shell Command to read and output data

Source: Internet
Author: User

Several Methods for shell scripts to read data:
1. keyboard input, default
2. Read from the file
3. Pipeline Command Transmission

Echo functions:
C: Do not wrap
F: Paper Feed
T: Skip
N: line feed
Escape, for example: ""/dev/rmt0 "" translated as, "/dev/rmt0"

Read: read information from a line of text on the keyboard or file and assign it to a variable.
[Development]/> read name
Hello I am a regular user
[Development]/> echo $ name
Hello I am a regular user
[Development]/>

Cat: function. 1. display the file content; 2. Create a file; 3. display the control characters.
1. display file content
Cat filename | more
Cat filename | pg
2. Create a file
Cat> filename
3. display control characters
Cat-v filename

Pipeline: You can pass the output of one command to another as the input through the pipeline.
Format: command 1 | command 2
For example:
[Development]/usr/xxxx/ytcclb> who | awk '{print $1 "t" $2 }'
Xxxx ttyp0
Xxxx ttyp1
Xxxx ttyp2
...
Xxxx ttyp55
[Development]/usr/xxxx/ytcclb> df-k | awk '{print $1}' | grep-v "Filesystem"
/Dev/root
/Dev/boot
[Development]/usr/xxxx/ytcclb> df-k | awk '{print $1}' | grep-v "Filesystem" | sed s' // dev // g'
Root
Boot
[Development]/usr/xxxx/ytcclb>

Tee command
Purpose: deliver one output copy to the standard output, and the other copy to the corresponding file.
Tee-a file
-A: append to the end of the file.
[Development]/usr/xxxx/ytcclb> who | tee who. out
Save the data found by the who command to the who. out file.

File redirection:
Command> filename redirects the standard output to a new file
Command> filename redirects the standard output to a file (append)
Command 1> fielname redirects standard output to a file
Command> filename 2> & 1 redirects the standard output and standard error to a file.
Command 2> filename redirects a standard error to a file
Command 2> filename redirects the standard output to a file (append)
Command> filename 2> & 1 redirects the standard output and standard error to a file (append)
Command <filename> filename2 uses the command file filename as the standard input,
Output with filename2 file as standard
Command <filename: The command is input using the filename file as the standard.
Command <delimiter reads data from the standard input until the delimiter is encountered.
Command <& m uses the file descriptor m as the standard input
Command> & m redirects standard output to file descriptor m
Command <&-Disable Standard Input

Redirection standard output
1. append the output of many commands to a file.
Ls-l | grep ^ d> files. out
Ls account *> files. out

[Development]/usr/xxxx/ytcclb> ls-l null.txt
-Rw-r -- 1 xxxx group 3 Nov 15 16:07 null.txt
[Development]/usr/xxxx/ytcclb> chmod u + x null.txt
Chmod: WARNING: cannot access + x: No such file or directory (error 2)
There is a space between u and + x!
[Development]/usr/xxxx/ytcclb> chmod u + x null.txt
[Development]/usr/xxxx/ytcclb> ls-l null.txt
-Rwxr -- r -- 1 xxxx group 3 Nov 15 16:07 null.txt

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.