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
python gui Interface examples -Python GUI Programming complete example vue element-ui Drop down menu with search algorithm : Longest common subsequence ( Output all longest common subsequences ) First knowledge Mongdb Data query ( three ) The problem of time type conversion “2021-01-20T10:09:11Z” Morphological processing gradient , Top hat , Black hat mean value - Implementation and application of variance model _python_ Data analysis _9 Wechat small program student course selection system app Design CCF A series of questions --2016 year 4 Month 1 Calculation of break point laravel The first mock exam is based on the "one to many" model. with,has,wherehas