Need a lot of help with a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a lot of help with a script
# 1  
Old 09-15-2008
Need a lot of help with a script

First off just would like to say hello I'm new to this forum but it looks very interesting and I'm sure I will learn a lot from the various people here.Smilie

I'm new to UNIX and more so scripting in it. I have an assignment for a class that's mostly done online and my teacher is of no help whatsoever telling us he would review steps to do it and hasn't. My group including me is clueless on how to accomplish our task I could really use a hand. We are using Putty and writing the scripts using VISmilie

1-
I need to write this particular script using the korn shell. It will take a number from the command line and perform the math in section 2(below). If no command line argument is given, the script should ask for a number between 1 and 20.

2-
The out of the script needs to be
a) The number
b) The square of the inputted number
c) The cube of the number
d) The square root of the number derived from (c)

So for example...It will ask
Please enter a number: "input 1-20"
You entered the number "XX"
The Square root of your number is "XXX"
The Cube of your number is "XXXXX"
The Qquare root of "XXXX" is "XX"

There's more kickers like if the number you enter isn't 1-20 it clears the screen and asks again for a number. Having an exit for a user other than entering a number. Using at least 1 sub function. Oye my head hurts just typing it.

Any help is seriously honestly appreciated.
# 2  
Old 09-16-2008
Asking about homework is specifically prohibited by the rules of this forum.

However if you have actually done some work and are stuck on a particular point, post your code and we can point you in the right direction.
# 3  
Old 09-16-2008
Code:
#!/bin/ksh
if [ $# -lt 1 ]
then
        echo "Please enter a number: input 1-20 \c"
        read Num
else
        Num=$1
fi
        echo "You entered the number " $Num
        Sqr=$(echo "$Num * $Num"  | bc -l)
        echo "The Square root of your number is " $Sqr
        Cub=$(echo "$Num * $Num * $Num"  | bc -l)
        echo "The Cube of your number is " $Cub
        result2=$(echo "sqrt($Cub)" | bc -l)
        echo "The Qquare root of " $Cub "is "$result2

# 4  
Old 09-16-2008
hi,
u can try this code...hope this will work..

#set -x
#!/bin/ksh
echo "enter a number from 1-20 : \c"
read number
echo you entered number : $number.
echo "square of your number is : `expr $number \* $number`."
echo "cube of your number is : `expr $number \* $number \* $number`."
echo "sqrt($number)"|bc > square_root
echo "square root of your number is:`cat square_root`"
rm square_root
exit 0


-subhendu-
# 5  
Old 09-16-2008
Quote:
Originally Posted by Annihilannic
Asking about homework is specifically prohibited by the rules of this forum.

However if you have actually done some work and are stuck on a particular point, post your code and we can point you in the right direction.

Oh man whoops way to make a first impressionSmilie

I dont have access to putty where Im at right now but Ill put up an update here in a few hours
# 6  
Old 09-16-2008
Quote:
Originally Posted by subhendu81
hi,
u can try this code...hope this will work..

#set -x
#!/bin/ksh
echo "enter a number from 1-20 : \c"
read number
echo you entered number : $number.
echo "square of your number is : `expr $number \* $number`."
echo "cube of your number is : `expr $number \* $number \* $number`."
echo "sqrt($number)"|bc > square_root
echo "square root of your number is:`cat square_root`"
rm square_root
exit 0

-subhendu-

Sorry I completely missed that rule not trying to make a bad impression Annihilannic.Smilie

Subhendu- I tried out your script it looks to work, what is the \c for at the end of line 3? Also this is cool because it will do any number not just 1-20 but i need to clear the screen and re ask for a number if it isnt.

Im gonna try out Manos next and see what I come up with
# 7  
Old 09-16-2008
Quote:
Originally Posted by manosubsulo
Code:
#!/bin/ksh
if [ $# -lt 1 ]
then
        echo "Please enter a number: input 1-20 \c"
        read Num
else
        Num=$1
fi
        echo "You entered the number " $Num
        Sqr=$(echo "$Num * $Num"  | bc -l)
        echo "The Square root of your number is " $Sqr
        Cub=$(echo "$Num * $Num * $Num"  | bc -l)
        echo "The Cube of your number is " $Cub
        result2=$(echo "sqrt($Cub)" | bc -l)
        echo "The Qquare root of " $Cub "is "$result2

Tried this syntax error at line 10 i couldnt figure it out
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print a python script down a list in a text file without printing a lot combinations

In a python script I have 2 files printing side by side on the same line. I want to have 1 of the files to be already displayed at once while the other file print down the list in the file and it still will produce new lines. I want to do it like that to reduce printing a lot of lines and... (0 Replies)
Discussion started by: bigvito19
0 Replies

2. Shell Programming and Scripting

Need a script for automation the convert a lot number audio files to another format

I have a lot number audio files in the MP3 proprietary format, I want to convert them to 'opus' the free and higher quality format, with keep metadata also. My selection command-line programs are SoX (Sound eXchange) for convert MP3 files to 'AIFF' format in order to keep quality and metadata*... (1 Reply)
Discussion started by: temp-usr
1 Replies

3. Shell Programming and Scripting

Need lot of examples

Hi, I need a word doc or pdf which contains lots of Shell Programming samples... This is for my open book examination, thanks in advance.. (2 Replies)
Discussion started by: karthikeayan
2 Replies

4. SCO

Very lot of systemcalls

I have one system running SCO MP4, whitch has sometimes a lot of system calls /s : CALLS/s: 23405 calls 0 forks 0 execs 6067 reads 78 writs 11975 Krwch PAGING/s: 0 pgins 0 pgots 5983 atchs 0 pflts 322 vfltsThese values are found with the tool rtpm ... (1 Reply)
Discussion started by: jkuiper
1 Replies

5. Shell Programming and Scripting

Rename a lot of files using shells script

Hi This is the list file that i have : The files is more than this. I will rename one by one file become like this : So just change the time stamp 200906 become 200905. Is it possible using script ? Thanks (3 Replies)
Discussion started by: justbow
3 Replies

6. Shell Programming and Scripting

chmod a lot of files

So i have about 600gb of data.. in which there are alot of directories and alot of files.. Im trying to put this on a ftp server.. So i want to set the permissions on the directories to be 755 and the permission on the files to be 644. So i used: find . -type d -exec chmod 755 {}\; and find .... (6 Replies)
Discussion started by: supermiguel
6 Replies

7. UNIX for Dummies Questions & Answers

help! I need a lot of help with unix!

Hey people, at first: I'm from Germany, so my english isn't very good, okay?;) I this september I start with my studys and now we use UNIX! I understand nothing. No, that's not right, at the beginnig I understood a little bit. But now we are at the .profile and there I have problem because my... (1 Reply)
Discussion started by: Tsukasu
1 Replies

8. Shell Programming and Scripting

rename a lot of files again

here I go again...kinda hard to explain so I apologize. I need to rename a bunch of files in a directory. I need to remove the first three characters of the filename, and then toward the end of the filename there is constant text inside of brackets. here is a demo (not for real) 'ls -1' of the... (11 Replies)
Discussion started by: ajp7701
11 Replies
Login or Register to Ask a Question