Shell script (. Sh): similar to the bat. File batch processing in Windows
It is more powerful than batch processing and is already a powerful programming language.
Echo "Please enter your name :";
Read fname;
Echo $ {fname} // {} can be omitted
The default data type is character.
Env view environment variables
Echo $ home view current user directory
Echo $ path
./Execute; you can also modify
VI/etc/profile
Add Path = $ path :.
Export the export path as a global variable. (You need to restart) so you don't need to add ./.
Echo 'date' shows the date (the quotation mark below the wavy line)
Expt 4 + 5 calculates 9, and there must be spaces around +
You can also: Echo $(4 + 5 ))
Example 1:
Echo "Please enter sore :"
Read score
If [$ score-lt 80] // if it is less than 80
Then
Echo "bad! ";
Elif [$ score Ge 80-A $ score-lt 90] // if it is greater than or equal to 80 and less than 90
Echo "Good! ";
Else
Echo "very good! ";
Fi // end judgment
Set the row number in VI: Set nu
: WQ save and exit
Example 2:
Echo "serices :"
Echo-n "1) ls" //-N indicates no line feed
Echo-n "2) ls-l"
Echo-n "3) Exit"
Echo "Please chioce [1-3]"
Read choice
Case $ choice in
1) ls ;;
2) ls-L ;;
3) exit;
*) Echo "wrong input ";;
Esac // end
Example 3:
Ecode = 1000
While [$ ecode-Le 1002] // [] There are spaces before and after
Do
Echo "Please enter info ecode = $ ecode"
Echo "Enter name :"
Read name
Echo "Enter age :"
Read age
Echo "Name: $ name age = $ age"> AA. dat
(Ecode = $ ecode + 1 ))
Done