Linux-shell case-for-while-Double Brackets-loop nesting-break-continue

Source: Internet
Author: User
Tags arithmetic case statement extend

Case: Flow control statements
• Loop Statement For...done statement
• Use (()) to extend the method of using arithmetic operations in the shell
• Looping statement nesting
• Jump out of the loop: Break and Continue
shift parameter Left SHIFT command
How to use functions in shell



Case statement; Select structure
Case SWITCH in
VALUE1)
Statement
.....
;;
Value2)
Statement
.....
;;
*)
Statement
.....
;;
Esac


#! /bin/bash

echo "***********************************"
echo "Please select your operation:"
echo "1 Copy"
echo "2 Delete"
echo "3 Backup"
echo "4 Quit"
echo "**********************************"
Read-p "Please select:" Op
Case $op in
C|C)
echo "Your selection is Copy"
;;
D|D)
echo "Your selection is Delete"
;;
B|B)
echo "Your selection is Backup"
;;
Q|Q)
echo "Quit"
;;
*)
echo "Invalide selection"


====================================================
Loop: Enter condition, exit condition

For statement
For variable in list: do

Loop body

Done

The declare command is a built-in command of Bash, which can be used to declare shell variables
The declare command allows variables to be assigned at the same time when declaring variable types
-R: Read-only
-I: Integer
-F: function
-A: Array
-X: Declares a variable to be exported as an environment variable of the script

While Loop statement
While condition
Do
Command
Done
====================================================
using (()) to extend the use of arithmetic operations in the shell

The previous method
When using "[]", you must ensure that there is a space between the operator and the arithmetic. Arithmetic can only be done with: expr command

The double-Brace "(())" Structure statement is an extension of the arithmetic and assignment operations in the shell.
Grammar:
(expression 1, expression 2 ... ))
Characteristics:
1, in the double bracket structure, all expressions can be like C language, such as: a++,b--, etc. A=a+1
2. In a double-brace structure, all variables may not be added: "$" symbol prefix.
3, the double parenthesis can carry on the logical operation, arithmetic
4. Double bracket structure expands the FOR,WHILE,IF condition test operation
5. Support multiple expression operations, separated by commas "," between the expressions


=====================================================
Loop statement nesting:


Jump out of the loop: Break and Continue
Break: Jump out of the loop
Continue: Skip this cycle for the next cycle


Shell Learning to practice more






Linux-shell case-for-while-Double Brackets-loop nesting-break-continue

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.