I wrote the first while loop of the dead loop

Source: Internet
Author: User

A long time not to come, not because of the abandonment of Linux, but to prepare for the preparation of the exam, temporary Linux. But lately there's been a little desire for yourself to write a cycle of death, and today there's something so-called inspiration that writes out the code:


#!/bin/bash

#

Uptime= ' Date +%s '

Sum=0

Add=1


While [$upTime-gt 0];d o

Let sum+= $add

Sleep 1

Echo $sum

Done


With the current total seconds time to compare with 0, because the variable is always greater than 0, the intrinsic mechanism is that the time will never go back, at least in general, machine time will not be set to 1970 ago, so while the condition after the judgment is always true, you can always execute the statement in the loop body.

And then wrote the following small program that shows the current time by the second:


#!/bin/bash

#

While [' Date +%s '-gt 0];d o

Date +%t

Sleep 1

Done

Gadgets are fun to run and work with you on a network of e-commerce websites like Xiaomi.

I wrote the first while loop of the dead loop

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.