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
Vue Export page as PDF file vscode Used in Sass, And automatically compile to CSS file use python Program draw some simple cartoon characters Python Execution sequence of decorator ajax Method encapsulation Mining virus processing record Give Way Mac How to set the system not to sleep all the time C Language life game source code ValueError: Shape of passed values is (6, 3), indices imply (6, 6)C++——list Super detailed introduction