Loop Control Structure of shell script Programming

Source: Internet
Author: User
Loop Control-for Loop syntax structure 1 forVariableinListdocommands & nb

Loop Control-for Loop

Syntax 1

For Variable in List

Do

Commands

Done

Syntax structure 2

For Variable in List; do

Commands

Done

This List can be a List, variable, command, etc.

A for Loop provides an element list in advance, and then uses variables to traverse the element list. Each time an element is accessed, a loop body is executed until the element access is completed.


1. The List in the for loop is a List

Eg1: displays the number of lines in the/etc/inittab,/etc/rc. d/rc. sysinit, and/etc/fstab files;

12345 #!/bin/bashforFile in/etc/inittab/etc/rc.d/rc.sysinit /etc/fstab;doRow=`wc-l $File | cut-d' '-f1`echo"$File has: $Row rows"done

Running result

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.