Code to read and output data using shell commands _linux shell

Source: Internet
Author: User
Tags chmod control characters

The shell script reads data in several ways:
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: the jump Grid
\ n: Wrapping Line
\ represents 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.

Copy Code code as follows:

[Jb51]/>read Name
Hello I am a regular user
[Jb51]/>echo $name
Hello I am a regular user
[jb51]/>

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:

Copy Code code as follows:

[Jb51]/usr/xxxx/ytcclb>who | awk ' {print $ ' \ t ' $} '
XXXX ttyp0
XXXX TTYP1
XXXX TTYP2
...
XXXX Ttyp55
[Jb51]/usr/xxxx/ytcclb>df-k | awk ' {print $} ' | Grep-v "FileSystem"
/dev/root
/dev/boot
[Jb51]/usr/xxxx/ytcclb>df-k | awk ' {print $} ' | Grep-v "filesystem" |sed s '/\/dev\///g '
Root
Boot
[jb51]/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.
[Jb51]/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

Copy Code code as follows:

Ls-l | grep ^d >>files.out
LS account* >> files.out

[Jb51]/usr/xxxx/ytcclb>ls-l Null.txt
-rw-r--r--1 xxxx Group 3 Nov 16:07 Null.txt
[Jb51]/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!

Copy Code code as follows:

[Jb51]/usr/xxxx/ytcclb>chmod u+x Null.txt
[Jb51]/usr/xxxx/ytcclb>ls-l Null.txt
-rwxr--r--1 xxxx Group 3 Nov 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.