shell script is meant shell script. The use of shell functions written a 'program', is essentially a plain text file.
note:
1. The instruction execution order from top to bottom, left to right.
2. instruction, multiple gaps between the options and parameters will be ignored.
3. If the read symbol enter the line starts executing instructions.
executable file:
Direct execution
Bash program to be executed: bash a or sh a
Sample one: create a shell script first world output Holle # ! / Bin / bash echo "Holle world" Exit 0 The first line: # ! / Bin / bash indication / bin / bash this file environment configuration file carried out
Small Exercise: Sample one: keyboard input surname, first name # / bin /! Bash the Read - the p-"Enter your name:" FirstName the Read - the p-"Enter your name:" LastName echo -e "\ the n-your full name is: $ {{LastName $ FirstName}} "
Exit 0
sample II: adding
! # / bin / the bash
echo -e" Please enter a two digit a, b, and then outputs the result C \ n-"
Read -p" Please input A: "A
Read -p" enter B: "B
C = $ (($ {$ A} + {B}))
echo -e" \ NC = {C} $ \ n-"
ESIT 0
The difference between the way the script execution:
1. Direct way of execution
Direct execution (relative path, absolute path), bash (or sh) to execute the script, are essentially in the original bash environment, create a new sub-program to perform bash shell script. Therefore, each of the variables within the subroutine or after operation, will not be returned to the parent in bash. If you want to change you can use the export command.
Conditional formula
1.if...then
1 monolayer. Syntax: if [Condition discriminant]; then the condition is satisfied, the instruction execution are non-empty if the sample a: input judgment is Y, or N (case insensitive) # / bin /! The bash Read - P "" V IF [ "$ {V}" == "the Y"] || [ "$ {V}" == "Y"]; the then echo "of variable INPUT IS $ {V}" Fi IF [ "$ {V}" == "N"] || [ "$ {V}" == "N"]; the then echo "of variable INPUT IS $ {V}" Fi Exit 0 2 multiplex. Method 1: syntax : IF [condition discriminant]; then the condition is satisfied, the instruction set executed else condition is not established, execute a set Fi IF[A discriminant conditions]; then the condition is satisfied, the instruction set executed elif [discriminant two conditions]; then the condition is satisfied, the instruction set executed else conditions are not established, execute a set fi