Bash is used for shell programming. Bash is free and easy to use. Bash-Bourne again shell
File named myshell. Sh
Before executing a file, you must first obtain the following permissions:
Chomod 777 myshell. Sh
1. display file content
#!/bin/bashcat myshell.sh
Run the following command:
./Myshell. Sh
Display result:
#! /Bin/bash
Cat myshell. Sh
2. count the number of lines, words, and characters in a file.
An existing file Vivi,
The file content is as follows:
Hello, world!
Vivi
The content of the shell file is as follows:
#!/bin/bashwc -l vivi wc -w viviwc -c vivi
Run the following command:
./Myshell. Sh
Display result:
Root @ vivi-Ideapad-Z460 :~ #./Myshell. Sh
3 Vivi
3 Vivi
20 Vivi
[Observed. The statistics on the number of rows include empty rows, and the empty rows in the middle include empty rows at the end. The number of words is determined by space or empty rows. Character statistics, not understanding... It seems that there is always one more .....]
WC Vivi
The result is 3 3 20 Vivi.
-L indicates the number of rows in line.
3. file copy
cp myshell.sh vivi
Vivi content has changed ....
4. File Movement
mv vivi cici
In this way, a Cici file is generated in your working directory. The content in the file is the same as that in Vivi ....
5. Sort the rows in the file
Sort filename
Result displayed on the terminal:
Root @ vivi-Ideapad-Z460 :~ #./Myshell. Sh
Hello, world!
Leehom
This is a wonderful world!
Vivi
6. Obtain the file type.
File Vivi
Root @ vivi-Ideapad-Z460 :~ #./Myshell. Sh
Vivi: ASCII text
7
The pipeline (|) uses the output of a command as the input of another command.
Grep "Leehom" Vivi | WC-l
Search Leehom in Vivi and count the number of lines displayed in Leehom.
10 redirection
Redirection: output the command result to a file instead of a standard output (screen ).
> Write the file and overwrite the old file.
> Add it to the end of the file to retain the content of the old file.
Use a backslash to output a command as a command line parameter of another command.