Unable to compile Shell Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unable to compile Shell Script
# 1  
Old 07-12-2010
Unable to compile Shell Script

Hi there,

I have written the shell script to illustrate arithmetic operations using case command as shown below:

Code:
#!/bin/bash
echo -n "Enter any two numbers :"
read a
read b
MENU="
Select any one option
1) Addition
2) Substraction
3) Multiplication
4) Division
5) Quit"
clear
$x=0;
while [ $x -ne 5 ]
do
echo "$MENU"
echo ""
echo -n "Please make your choice "
read x
echo ""
case $x in
1) echo $[a+b] ;;
2) echo $[a-b] ;;
3) echo $[a*b] ;;
4) echo `$[a/b]| bc -l `;;
5|q|Q) exit 0 ;;
6) clear
echo "Please choose from the alternatives 1, 2, 3, 4 or 5"
sleep 1 ;;
esac
done
echo ""

Problem is when even in compiling this script it takes the input and shows the following error:
Code:
math.sh: line 15: =0: command not found
math.sh: line 17: [: -ne: unary operator expected

I would be more than happy if anyone can help me out.

Thank you.

Moderator's Comments:
Mod Comment You go to the trouble of adding [b]...[/b] to highlight code, when it's just as easy using [code]...[/code]. Please use the [code]...[/code] option next time. Thanks

Last edited by Scott; 07-12-2010 at 01:57 PM.. Reason: Code tags
# 2  
Old 07-12-2010
Quote:
Originally Posted by grc
Code:
$x=0;

I guess you wanted:

Code:
x=0

# 3  
Old 07-12-2010
Power problem compiling shell script

Thank you dr.house

Those errors got rectified, however when I am try to select 4th option (Division) it shows the following error.

Code:
"math.sh: line 28: 0: command not found"

I even changed that option to

Code:
"4) echo $[a/b] ;;"

In this case it not returning decimal values, but instead it is returning zero.

Help me out please

Last edited by Scott; 07-12-2010 at 01:58 PM.. Reason: Code tags
# 4  
Old 07-12-2010
I had no idea that this would work:

Code:
$ a=1
$ b=2
$ echo $[a+b]
3

Weird, but I learnt something new!

Not sure that this will work:
Code:
4) echo `$[a/b]| bc -l `;;

Might need to be more like:
Code:
4) echo $[a/b]| bc -l ;;

(without the backquotes)

But this is surely wrong:
Code:
$x=0;

Should maybe be:
Code:
x=0

This User Gave Thanks to Scott For This Post:
# 5  
Old 07-12-2010
Quote:
Originally Posted by grc
Those errors got rectified, however when I am try to select 4th option (Division) it shows the following error
How about:

Code:
echo $a/$b | bc -l

This User Gave Thanks to dr.house For This Post:
# 6  
Old 07-13-2010
solution to division option works..

Thank you again dr.house...Smilie

Your solution works..

Regards
G Ravi Chandran
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

2. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

3. UNIX for Dummies Questions & Answers

unable to start shell script

Hi, Pleasse could someone advise why i'm getting this error below - No such file or directory dev6:$ ls -ltr ReleaseManagement.sh -rwxr-xr-x 1 dev fix 4830 Aug 22 11:13 ReleaseManagement.sh dev6:$ ./ReleaseManagement.sh : No such file or directory dev6:$ thank you (2 Replies)
Discussion started by: venhart
2 Replies

4. UNIX for Dummies Questions & Answers

Re:Unable To Execuate Shell Script

Hi , I Am Getting The Below Error When Executing A Shell Script (Running Red Hat Linux 5 As Guest And Host Is Windows 7) Logging As Root User !/bin/ksh: not found This Are The Steps I am Following For Saving And Executing The Script File. 1).Opening Terminal 2).Issue Command vi... (2 Replies)
Discussion started by: anudeepkumar123
2 Replies

5. Shell Programming and Scripting

compile a shell script

How can i compile a KSH shell script. I Dont want to execute it. I just need to compile it . Any Help sincerly appreciated. (5 Replies)
Discussion started by: panyam
5 Replies

6. Shell Programming and Scripting

unable to exit from a shell script

Hi All, I am unable to exit from a shell script using the below code: #!/bin/ksh passchk() ( if ;then echo "Password validated" else echo "Wrong password Quiting the application..." exit 0#not working fi ) passchk (Note:"finalresult" passed to the passchk... (2 Replies)
Discussion started by: Sreejith_VK
2 Replies

7. Shell Programming and Scripting

Still unable to compile pro*c program

I am unable to compile the programs, I am able to compile .pc to .c but later part of the compilation from .c to executalbe i am unable to do. Here is the way i am doing make -f $LIB_LIB/makefile.templ sample I am getting the following errors, which environment and where to set to point... (1 Reply)
Discussion started by: satvd
1 Replies

8. UNIX for Dummies Questions & Answers

Unable to compile the c programme in unix

Hi, My name is vreddy and I am learning c language now and written one programme on vi editor. how do I compile the programme please give me some advice and that would be helpfull for me. thanks vre (10 Replies)
Discussion started by: vasudeva
10 Replies

9. Shell Programming and Scripting

unable to do mailx from shell script

Hi From within a shell script my mailx doesnt seem to work...can somebody tell me what is wrong... #!/bin/ksh #Script to verify wheather all databases listed are up and running #Script works with Oracle8 and above databases #Script has to be run by ./scriptname DBA=xiamin@unix.com echo... (3 Replies)
Discussion started by: xiamin
3 Replies

10. HP-UX

Unable to compile ANSI compatible code on HP-UX

Hi!!, my HP-UX - 10.2 compiler doesnt appear to support ANSI style of coding. On compiling my C code, it flags error messages like error 1705: Function prototypes are an ANSI Feature Is it a generic problem with the HP compiler or do I need to use some special switches on the command... (9 Replies)
Discussion started by: jyotipg
9 Replies
Login or Register to Ask a Question