For process Control in the shell

Source: Internet
Author: User

For loop:

Used in the shell for looping. Similar to for in other programming languages, but somewhat different. The For loop is the most common syntax structure in bash.

Common format Format One

For variable

Do

Statement

Done

Format Two

For variable in list

Do

Statement

Done

Format three

for (variable = initial value; condition judgment; variable change)

Do

Statement

Done


If do and for want to be on the same line, you need this

For ARG in [list];d o

Commands ...

Done

ARG will get the variable in the list sequentially


***************************************************************************************************

1, for ((i=1;i<=10;i++));d o echo $ (expr $i \* 4);d One
2. Commonly used in shell is for I in $ (seq)
3, for i in ' ls '

4, for I in ${arr[@]}  &NBSP;
5, for I in $*; do&NBSP;
6, for File in/proc/sys/net/ipv4/conf/*/accept_redirects; do&NBSP;
7, for I in F1 F2 F3;d o 
8, for I in *.txt&NBSP;
9, for I in $ (ls *.txt) &NBSP; the
for in statement is used in combination with" ' and $ (), with the flaw of "or $ () that would be a row-by-line, which is actually a string array of
10, list=" Rootfs usr data data2 "&NBSP;
for D in $LIST; Do&NBSP;
    Use the for in statement to automatically traverse the string by space, &NBSP;
11, for I in {1..10}
12, for I in Stringchar {1..10}
13, awk ' Begin{for (i=1 ; i<=10; i++) Print i} '

Note: The For loop notation in awk is the same as the C language

***************************************************************************************************

For process Control in the shell

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.