Shell finishing (32) = = = Two small examples of nested loops

Source: Internet
Author: User

(1) The shell prints the pattern as shown.

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/07/9D/wKiom1nMh-ygSI1MAAAj5j4UcHs376.png-wh_500x0-wm_ 3-wmp_4-s_3715701053.png "title=" capture. PNG "alt=" Wkiom1nmh-ygsi1maaaj5j4uchs376.png-wh_50 "/>



The shell code is as follows:

#!/bin/bash


echo "-"

For i in ' seq 9 '

Do


For x in ' seq $i '

Do

Echo-n ""


Done

echo "|"

Echo

For y in ' seq $i '

Do

Echo-n ""

Done

echo "-"

Done

echo "|"

Echo



Two

A ball from 100 meters height of the free fall, each landing after jumping back to the original height of half, and then fall, begging for it in the 10th time on the landing, total after how many meters? How high is the 10th rebound?

The shell code is as follows

#!/bin/bash


x=100

For i in ' seq 10 '

Do

x= ' awk ' begin{printf ' $x '/2} '

Done

Echo $x


Output Result:

[Email protected] ding]# bash 22.sh

0.097656

[Email protected] ding]#


This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1969406

Shell finishing (32) = = = Two small examples of nested loops

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.