Shell Scripting Shell Scripting a basic introduction to the basics

Shell Scripting basic introduction

 

Shell Scripting

One. What is Shell Script

Shell script is a script written for the shell. We usually replace the shell script shell.

two. Shell scripting environment

Shell as long as one can write code in a text editor and a script interpreter to explain the implementation of the program can be written. Shell divided into many versions, such as: sh, tsh, csh, tcsh, ash, bash, which bash shell is the Linux default shell. shell are generally stored in / bin or / user / bin directory, we can open a terminal in / bin or / user / bin directory, use the command cat / etc / shells command to see what our system is available for linux shell Yes.

three. The use of shell scripting

1. Create a shell script

Use vi test (custom script name) into the name of the script editor page of the script for the test, suffix .sh.

  1. Edit Script

i on the keyboard to enter edit mode, the first line of the script is #! / bin / bash, where #! is an agreed mark means that the script interpreter to execute what is required, then we started to edit the script, use the echo command output I love Hunan Institute of Science and Technology. Then press the Esc key, enter: wq to save and exit the editor!.

 

 

3. Grant the executable permission

Creating a good script needs executable permissions or as an interpreter available parameters that we use, which I'll show the first method, enter the command chmod + x ./test.sh, then we enter ./test.sh execute the script, where. represents the current directory, execute test.sh files in the current directory.

three. Shell Variables

  1. Shell definition of variables

When we define a variable, the variable name without the dollar sign ($), such as: your_name = "wangyi"

Shell variable names must be composed of numbers, letters, underlined, can not start with a number. For example a_1, a1. We can also assign values ​​to variables with statements such as: for file in `ls / etc` or for file in $ (ls / etc)

The above statement will name the file / etc directory out of the loop.

  1. Use Shell variables

Only you need to add $ variables we define it, such as echo $ a1. When a plurality of input characters, plus we want to use a shell variable linux {} facilitate better recognition system, such as echo $ {a} 1, the habit is very useful.

Shell Scripting

One. What is Shell Script

Shell script is a script written for the shell. We usually replace the shell script shell.

two. Shell scripting environment

Shell as long as one can write code in a text editor and a script interpreter to explain the implementation of the program can be written. Shell divided into many versions, such as: sh, tsh, csh, tcsh, ash, bash, which bash shell is the Linux default shell. shell are generally stored in / bin or / user / bin directory, we can open a terminal in / bin or / user / bin directory, use the command cat / etc / shells command to see what our system is available for linux shell Yes.

three. The use of shell scripting

1. Create a shell script

Use vi test (custom script name) into the name of the script editor page of the script for the test, suffix .sh.

  1. Edit Script

i on the keyboard to enter edit mode, the first line of the script is #! / bin / bash, where #! is an agreed mark means that the script interpreter to execute what is required, then we started to edit the script, use the echo command output I love Hunan Institute of Science and Technology. Then press the Esc key, enter: wq to save and exit the editor!.

 

 

3. Grant the executable permission

Creating a good script needs executable permissions or as an interpreter available parameters that we use, which I'll show the first method, enter the command chmod + x ./test.sh, then we enter ./test.sh execute the script, where. represents the current directory, execute test.sh files in the current directory.

three. Shell Variables

  1. Shell definition of variables

When we define a variable, the variable name without the dollar sign ($), such as: your_name = "wangyi"

Shell variable names must be composed of numbers, letters, underlined, can not start with a number. For example a_1, a1. We can also assign values ​​to variables with statements such as: for file in `ls / etc` or for file in $ (ls / etc)

The above statement will name the file / etc directory out of the loop.

  1. Use Shell variables

Only you need to add $ variables we define it, such as echo $ a1. When a plurality of input characters, plus we want to use a shell variable linux {} facilitate better recognition system, such as echo $ {a} 1, the habit is very useful.

Guess you like

Origin www.cnblogs.com/wycom/p/11891966.html