Shell Script Integer Division

Shell script that uses a for.do loop to list the numbers from 1 to 100 that are divisible by 3 to find their sum and outputs a file named sum.sh

#! /bin/bash

sum=0

for i in {1..100}

do

if [ $(( $i % 3 )) -eq 0 ]

then

echo $i

sum=$(( $sum + $i ))

fi

done

echo “sum is: $sum”

saved as sum.sh

How shell script extracts integer parts

[root@localhostzhaoru]#b.shshell.sh

1331.2

[root@localhostzhaoru]#catshell.sh

#! /bin/bash

a=1.3

speed=`echo${a}*1024|bc`

echo$speed

Write a program in Shell Script to display the sum of numbers divisible by 3 or 7 up to 100.

#! /bin/bash

sum=0

for i in `seq 1 100`;do

a=$[$i%3]

b=$[$i%7]

if [ $a -eq 0 ]||[ $b -eq 0 ];then

sum=$[$sum+$i ]

fi

done

echo $sum

How does a linuxShell script accomplish printing out numbers divisible by 3 in 1000?

#! /bin/bashfor((i=1;i<1000;i++))doif((i%3==0))thenecho$icontinuefidone just like this A Linux has problems with line breaks, just be able to read it.

Write a shell script that calculates the sum of numbers divisible by 3 within 100 using a loop and the continue keyword, and it always runs with an error

I got your program down and it runs with no errors, so you can see if your /bin/sh is a bash,

ls-l/bin/sh

See if it’s pointing to a bash, if it is add

set-x at the beginning of the script

and then run it to see the output, after set-x it will trace and print out the bash, set-x will trace and print out the output, set-x will print out the bash. bash,

set-x

at the beginning of the script and run it to see the output,

set-x will print out a trace of the execution of the bash shell,

you can turn it off with set+x.