Write a script:
Enter one of the three parameter 0,1,2,3
Input 3; Calculates the number of positive integers within 100 that can be divisible by 3;
Enter 2; calculate all the numbers of all even numbers within 100;
Enter 1; calculate all the odd numbers within 100 and all;
Input 0; Calculates the and of all integers within 100;
Code
#!/bin/bash#declare -i sum=0if [ $1 == 3 ];then for i IN {1..100};d o if [ $[$I%3] -eq 0 ];then sum=$[$SUM + $I] fi done echo $SUMelif  [ $1 == 2 ];THEN  FOR I IN {1..100};d o if [ $[$I%2] -eq 0 ];then sum=$[$SUM + $I] fi done echo $SUMelif [ $1 == 1 ]; THEN  FOR I IN {1..100};d o if [ $[$I%2-1] -eq 0 ];then sum=$[$SUM + $I] fi done echo $SUMelif [ $1 == 0 ];then for i in  {1..100};d O  &Nbsp; sum=$[$SUM + $I] done echo $SUMelse echo "usage: ./ for1003.sh arg [0,1,2,3] "fi
Execution results
[[email protected] ~]#/for1003.sh 0 5050[[email protected] ~]#./for1003.sh 12500[[email protected] ~]#./for1003 . SH 22550[[email protected] ~]#./for1003.sh 31683[[email protected] ~]#./for1003.sh 4Usage:./for1003.sh ARG [0,1,2,3]
Bash Simple for loop 2