Linux Shell syntax

Source: Internet
Author: User
Tags case statement

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! '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.