shell script while Loop instance : calculation 1 reach 100 And

#!/bin/bash

# The last line means to declare this script Using shell name , Symbol #! Combination means declaration shell Symbol # It's for annotation

i=1

temp=101

sum=0

while   [   $i   -ne    $temp   ]         be careful : Here we must note that there must be a space after the left bracket and before the bracket , Otherwise, it will report an error

do

sum=$(($sum + $i))       be careful : There must be two brackets here

i=$(($i+1))

echo    $sum         Output at terminal sum Value of

done

attach : If you need to output content to the terminal during the execution of the script, you can add statements to the script echo    calculation 1 reach 100 And

If you need to execute the command , Add the command to execute directly in the script ,

If you need to do it every other second, add sleep   1     The command is delayed by one second ,

If you need to output content to a text file during execution, you can add

echo     calculation 1 reach 100 And >>filename.txt  ( To text file filename.txt Medium output “ calculation 1 reach 100 And ”)

Technology
©2020 ioDraw All rights reserved
django Do not close CSRF middleware , Custom through CSRF Tested post request Understanding neural network machine translation in three minutes error: (-215:Assertion failed) Solution ETL tool kettle And datax Comparison test cases Oracle to Oracle Tiktok The matrix - Code rain ( Free delivery ) Interview questions : Handwritten list ( Include reverse linked list )-bash The Trojan horse , Have you ever met one ? Implementation and challenge of metadata service in data Lake PHP call shell command Notes on core principles of reverse engineering ( One )——Hello World-1