Donate SIGN UP

Shell Script (Unix) Help Please.

Avatar Image
xAsh | 20:02 Thu 06th Dec 2007 | Technology
5 Answers
I am trying to write a script whereby i ask a user to input a number and then output a table of multiplication for the number given. So if "6" was entered, it would print out:

1x6=6
2x6=12
3x6=18
4x6=24
(up to 10 x the number input).


I've created other shell scripts but i just cant get my head around this.

I've got so far:

#!bin/ksh
echo "Enter a number"
read number


Thats it, im finding this really difficult lol. I dont know if any let, read, if, then or else, case statements needed. Any help please?


tnx
Gravatar

Answers

1 to 5 of 5rss feed

Best Answer

No best answer has yet been selected by xAsh. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
(I can't remember bash shell syntax.)

for (i=1; i<11; i++) {
echo i + "x" + number + "=" + (i * number)
}
W "enter number "
R n
F i=1:1:10 D
.W n," times ",i, " = ", n*i,!
.Q
Q
; or similar


Question Author
k cheers.

when i do :

#!/bin/ksh
for (i=1; i<11; i++) {
echo i + "x" + number + "=" + (i * number)
}

it says theres an unexpected at line 4 with the brackets?

why is this? tnx
I don't know if that's the correct syntax. Treat it as pseudo-code. The correct syntax is probably more like whiffey's example.
This will do it, but lol I haven't done any shell scripting for quite a while !

#!/bin/ksh
echo "Enter number: "
read number
let x=1
while [[ $x -lt 11 ]]
do
let mult=number*x
echo $x "times" $number " = " $mult
let x=x+1
done

There are other ways (of course being Unix)

for i in 1 2 3 4 5 6 7 8 9 10
do
echo $i
done

The language I gave the previous answer in is one called M (MUMPS). It is absolutely brilliant and I use it all the time (on a Solaris platform) in preference to shell or perl for all general purpose data manipulation.

1 to 5 of 5rss feed

Do you know the answer?

Shell Script (Unix) Help Please.

Answer Question >>

Related Questions

Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.