Shell for, while usage

Source: Internet
Author: User

#数字段形式
For i in {1..10}
Do
Echo $i
Done

#详细列出 (characters and not many items)
For File in 1 2 3 4 5
Do
Echo $File
Done

#对存在的文件进行循环
For shname in ' LS *.sh '
Do
Name= ' echo ' $shname | Awk-f. ' {print '} '
Echo $name
Done

#查找循环 (This method can also be used when the LS data is too large)
For Shname in ' find. -type f-name "*.sh"
Do
Name= ' echo ' $shname | awk-f/' {print $} '
Echo $name
Done

# (Syntax loop--a bit like C syntax, but remember the double parenthesis
For ((i=1;i<100;i++))
Do
if ((i%3==0))
Then
Echo $i
Continue
Fi
Done

#seq形式 starting from 1
For i in ' SEQ 100 '
Do
if ((i%3==0))
Then
Echo $i
Continue
Fi
Done

#while循环注意为方括号 [], and note the space
Min=1
max=100
While [$min-le $max]
Do
Echo $min
min= ' expr $min + 1 '
Done

#双括号形式, the internal structure is a bit like the C syntax, note assignment: i=$ (($i + 1))
I=1
while (($i <100))
Do
if (($i%4==0))
Then
Echo $i
Fi
i=$ (($i + 1))
Done

# Loop Control Statements
The # Break command does not perform the current loop within the body break, and the following statement exits from the current loop.
# Continue command is a program that ignores the following statement in this body, starting from the loop header

Shell for, while usage

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.