1. Build and run the shell program
What is a shell program? Simply put, a shell program is one that contains several lines
File for Shell or Linux commands.
As with programs written in high-level languages, writing a shell program requires a text editor. such as VI.
In the text editing environment, according to the Shell's syntax rules, enter some shell/linux command line, form a complete
's Program Files.
There are three methods of executing shell program Files
(1) #chmod +x file (in/etc/profile, add export Path=${path}:~/yourpath, you can run directly under the command line, like the normal command)
(2) #sh file
(3) #. File
(4) #source file
When writing a shell, the first line must indicate that the system needs that shell to explain your shell program, such as: #! /bin/bash,
#! /BIN/CSH,/BIN/TCSH, or #!. /bin/pdksh.
Variables in the 2.shell
(1) Common system variables
$ #: The number of command line arguments to save the program
$ ? : Save the return code of the previous command
$0: Save program Name
$ *: to ("$ $ ...") To save all the input command-line arguments in the form
$ @: to ("$" ...) To save all the input command-line arguments in the form
(2) Defining variables
Shell language is an interpretive language of non-type, and it is not necessary to declare variables in advance when programming in C++/java languages. Give a
A variable is actually defined as a variable.
In all shells supported by Linux, you can assign values to variables using the assignment symbol (=).
Such as:
Abc=9 (Bash/pdksh cannot leave spaces on both sides of the equals sign)
Set ABC = 9 (tcsh/csh)
Because the variables of the shell program are of no type, users can use the same variable and store the characters sometimes
Integer.
Such as:
NAME=ABC (Bash/pdksh)
Set name = ABC (TCSH)
After the variable is assigned, simply precede the variable with a $ to reference.
Such as:
Echo $ABC