Computing.Net > Forums > Linux > begginner shell script help ASAP!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

begginner shell script help ASAP!

Reply to Message Icon

Name: vampiretodd
Date: February 17, 2003 at 16:48:17 Pacific
OS: win98
CPU/Ram: 315
Comment:

hi guys, i really need some help asap. Im taking an OS class and we barely skimmed over Linux. We were asked a homework question that for the life of me i have no idea how to do. the qestion is...
write a shell script that accepts a number from the user and displays the squares of all numbers from 1 up to that number as follows:

1 square=________
2 square=________
:
:
n square=________
(n is the number entered)

PLease help if possible. its due tomorrow and i havent even begun to figure it out.
Thanks!
Todd



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: February 17, 2003 at 18:26:08 Pacific
Reply:

#!/bin/ksh
if [ $# -gt 0 ] ; then
i=1
square_cnt=$1
while [ $i -le $square_cnt ] ; do
((square = $i * $i ))
echo "$i square = $square"
((i = i + 1))
done
else
echo "ERROR. Please enter an integer"
fi

You should make a sanity check to make sure someone does not pass a non-integer on the command line. Hope you get a good grade. O'Reilly has a nice book on KSH. For future questions, the unix list here is more adept at scripting questions.


0

Response Number 2
Name: vampiretodd
Date: February 17, 2003 at 19:13:57 Pacific
Reply:

Thanks! I really appreciate the help!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


floppy error message periodically ping isp



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: begginner shell script help ASAP!

advanced shell script help www.computing.net/answers/linux/advanced-shell-script-help/17749.html

shell script help www.computing.net/answers/linux/shell-script-help/15420.html

Shell Script - help www.computing.net/answers/linux/shell-script-help/21347.html