Shell scripts can read data in the following ways:
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
\ Indicates 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.
Copy codeThe Code is 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 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:
Copy codeThe Code is as follows: [jb51]/usr/xxxx/ytcclb> who | awk '{print $1 "\ t" $2 }'
Xxxx ttyp0
Xxxx ttyp1
Xxxx ttyp2
...
Xxxx ttyp55
[Jb51]/usr/xxxx/ytcclb> df-k | awk '{print $1}' | grep-v "Filesystem"
/Dev/root
/Dev/boot
[Jb51]/usr/xxxx/ytcclb> df-k | awk '{print $1}' | grep-v "Filesystem" | sed s'/\/dev \// /G'
Root
Boot
[Jb51]/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.
[Jb51]/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.
Copy codeThe Code is as follows: ls-l | grep ^ d> files. out
Ls account *> files. out
[Jb51]/usr/xxxx/ytcclb> ls-l null.txt
-Rw-r -- 1 xxxx group 3 Nov 15 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 is a space between u and + x!
Copy codeThe Code is 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 15 16:07 null.txt