Linux Shell is a powerful script program with simple syntax. The following is an executable sh script, covering common shell syntax and usage. Understanding it is equivalent to getting started.
#! /Bin/bash
# Title:
# Date :?
# Author: Made by HFX
Echo '[test @ test] # sh [-nvx] scripts
-N: do not execute scripts. query the syntax in scripts. If there is an error, list it!
-V: display the content of scripts on the screen before executing scripts;
-X: displays the used scripts on the screen, slightly different from-V'
Echo 'escape character \ followed by a symbol'
Hello = Hello \\! \ How \ are \ you \\?
Echo $ hello
Echo 'difference between single quotes and double quotes: $ in single quotes only represents $, and $ in double quotes represents variable'
Name = "v. Bird"
Myname1 = "My name is $ name"
Myname2 = 'My name is $ name'
Echo $ name
Echo $ myname1
Echo $ myname2
Echo 'display declaration variable declare-I'
Declare-I A = 3
Declare-I B = 4
# Declare-I c = $ A * $ B
# Echo $ C
Echo 'interface'
Echo 'cin you name :'
Read name
Echo 'your name is :'
Echo $ name
Echo 'Shell program parameters'
Echo '$0 indicates the 0th parameters after the sh program, $1 ...... '
Echo 'condition statement'
Echo 'continue please CIN: Y or y'
Read YN
If ["$ YN" = "Y"] | ["$ YN" = "Y"]; then
Echo "script is running ..."
Else
Echo "Stop! "
Fi
Echo 'case statement'
Echo "press your select one, two, three! "
Read choice
Case $ choice in
One)
Echo "your choice is one"
;;
Two)
Echo "your choice is two"
;;
Three)
Echo "your choice is three"
;;
*)
Echo "usage {one | two | three }"
# Exit 1
Esac
Echo 'loop statement ()'
Echo '1 + ...... + 100'
Declare-I s # <== variable Declaration
For (I = 1; I <= 100; I = I + 1 ))
Do
S = S + I
Done
Echo "1 +... + 10? 0 = $ S"
Echo 'do... while'
Echo "Press Y/y to stop"
Until ["$ YN" = "Y"] | ["$ YN" = "Y"]
Do
Read YN
Done
Echo "stop here"
Echo 'test shell end! '