Shell commands read data and output data

Source: Internet
Author: User
Tags chmod control characters

Several ways the shell script reads data:
1. keyboard input, default
2. read from the file
3. Pass through Pipeline command

Functions of Echo:
C: No Line change
F: Paper Feed
T: Jump lattice
N: Line Wrap
Represents an escape, for example: "/dev/rmt0" translates to, "/dev/rmt0"

READ: Reads information from a line of text in a keyboard or file and assigns it to a variable.
[Development]/>read Name
Hello I am a regular user
[Develop]/>echo $name
Hello I am a regular user
[Development]/>

Cat: Function, 1. Display the contents of the file, 2. Create a file, 3. Display control characters.
1. Display the contents of the file
Cat FileName | More
Cat FileName | Pg
2. Create a file
Cat > FileName
3. Display control characters
cat-v filename

Pipe: The output of one command can be passed to another command as input through a pipe.
Form: Command 1 | Command 2
For example:
[Development]/usr/xxxx/ytcclb>who | awk ' {print ' t ' $} '
XXXX ttyp0
XXXX TTYP1
XXXX TTYP2
...
XXXX Ttyp55
[Development]/usr/xxxx/ytcclb>df-k | awk ' {print $} ' | Grep-v "FileSystem"
/dev/root
/dev/boot
[Development]/usr/xxxx/ytcclb>df-k | awk ' {print $} ' | Grep-v "filesystem" |sed s '//dev///g '
Root
Boot
[Development]/usr/xxxx/ytcclb>

Tee command
Function: Transfer one copy of output to standard output and another copy to the corresponding file.
Tee-a file
-A: Append to end of file.
[Development]/usr/xxxx/ytcclb>who | Tee who.out
Save the data that the WHO command finds to the Who.out file.

File redirection:
Command > FileName redirect standard output to a new file
Command >> filename REDIRECT standard output to a file (append)
Command 1 > Fielname redirect standard output to a file
Command > FileName 2>&1 redirects the standard output to a file with standard errors
Command 2 > FileName redirect standard errors to a file
Command 2 >> filename REDIRECT standard output to a file (append)
Command >> filename 2>&1 redirects the standard output to a file (append) with the standard error
Command < filename >filename2 the command command to the filename file as the standard input,
Use filename2 file as standard output
command < filename input command to filename file as standard
Command << delimiter reads from the standard input until it encounters the delimiter delimiter
Command <&m the file descriptor m as the standard input
Command >&m redirects standard output to the file descriptor m
Command <&-turn off the standard input

REDIRECT 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--r--1 xxxx Group 3 Nov 16:07 null.txt
[Dev]/usr/xxxx/ytcclb> chmod u +x null.txt
Chmod:WARNING:cannot access +x:no such file or directory (Error 2)
There are spaces between U and +x!
[Develop]/usr/xxxx/ytcclb>chmod u+x null.txt
[development]/usr/xxxx/ytcclb>ls-l null.txt
-rwxr--r--1 xxxx Group 3 N OV 16:07 null.txt

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.