Shell for Learning

Source: Internet
Author: User
#!/bin/bash

for_1 () {
    echo ' for 1 show item ' for
    var in item1 item2 ... itemn do
        Echo ${var};
    Done
}

for_2 () {
    echo ' for 2 show 1~5 ' for
    loop in 1 2 3 4 5
    do
        echo ' The value is: ${loop} ' 
  done
}

for_3 () {
    echo "for 3 show string array" for STR in ' This is
    a string ' " C17/>do
        Echo ${str}

for_4 () {
    echo "for 4 show string" for
    str in "' This is a string ' This is a number ' ' Does
        echo ${str}

for_5 () {
    echo "for 5 show ls" for
    file I n ' ls./'
    do
        echo ${file}

for_6 () {
    echo ' for 6 show () '
    for (i=1;i<=5;i+ +))
    do
        echo "This is the first $i call";
    Done

}

for_1
for_2
for_3
for_4
for_5
for_6

# for use the two types of command for
file in $ (LS); Do Echo ${file}; Done for
file in ' ls ';;d one of Do Echo ${file}

Results:

for 1 show item item1 item2 ... itemn for 2 show 1~5 the value is:1 the value is:2 the value  Is:3 the value is:4 the value Is:5 for 3 show string array This is a string this is a number to 4 show string ' This is a string ' "is" a number ' for 5 show LS array.sh for.sh function.sh if.sh op.sh params.sh read.sh string.sh TRAP.S H varaiable_assignment.sh while.sh XAA for 6 show () This is the 1th time call this is the 2nd call this is the 3rd call this is 4th call this is the 5th call array.sh for.sh Fun
ction.sh if.sh op.sh params.sh read.sh string.sh trap.sh varaiable_assignment.sh while.sh xaa array.sh for.sh function.sh if.sh op.sh params.sh read.sh string.sh trap.sh varaiable_assignment.sh while.sh xaa 
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.