Can anyone help with SHELL?

Currently reading:
Can anyone help with SHELL?

Joined
Apr 7, 2011
Messages
3,555
Points
716
Location
Rotherham
Basically, I just need this into a shell expression:

n x (n + 1) x (2n + 1)
______________________
6

My existing script uses a simple calcualtion but need to implement the above:

Code:
#!/bin/sh
 
echo "\n"
echo -------- Squares on a chessboard Calculator -------"\n"
 
echo "Simply, this calculator will return the number of
squares on a chessboard, according to the size of
the square chosen\n"
 
echo "Please enter a square size (1-8)...\n"
read SQUARE_SIZE
 
NO_SQUARES=`expr $SQUARE_SIZE + 5`
echo $NO_SQUARES

exit 0
~
 
scratch that, but you may still be able to help.

Iv done a similar thing but a different way, you any good at converting from perl to shell? just 'sh' or 'ksh' doesnt really matter. I just wanna go from perl to shell:

perl:

Code:
#!/usr/bin/perl
 
$square_fits = 1;
$total_squares = 0;
 
while ($square_fits < 9) {
      $squares = ($square_fits **2);
      print "$squares\n";
      $total_squares = ($total_squares + $squares);
      $square_fits ++;
}
 
print "$total_squares\n";

and this is what iv got for sh, but it doesnt work :(

Code:
#!/bin/sh
$square_fits=1
$total_squares=0
while [ $square_fits -le 9 ]
do
   $squares = `expr  $square_fits * $square_fits`
   echo "$squares"
   $total_squares = `expr $total_squares + $squares`
   $square_fits = `expr $square_fits + 1`
done
 
Back
Top