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!
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
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
Summary: i need help with a shell script that passes a variable. why does this not work?: echo $`echo 1` i want this to produce the same result as echo $1 but instead of the first option given at the command...
Summary: Im starting to learn bash. i lvoe it. im trying to do something but want the easy way arround. I made this script: #!/bin/bash #Author = MrJake # #Desc = will display a chmod list # # #Created on Mon ...
Summary: hi, I want to write a shell script which will execute some commnds in the script and create a resulted variable with all the results. e.g. ----------------- #!/bin/bash year = 'date +%Y' month = 'date...