Problem in excuting my First Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in excuting my First Shell Script
# 1  
Old 01-10-2010
Problem in excuting my First Shell Script

Hi
i am a newbie to unix /Linux .Please help
I have a following script which says that there is a syntax error Smilie

My program is


echo Enter two Numbers
read a b
if [ $a gt $b]
echo First is greater
else
echo Second is greater
fi
# 2  
Old 01-10-2010
Code:
echo Enter two Numbers 
read a b 
if [ $a -gt $b ] # space before ]
then
echo First is greater
else 
echo Second is greater
fi

What if the two numbers are the same?!
# 3  
Old 01-10-2010
[/code]What if the two numbers are the same?![/QUOTE]
Smilie

Thank you very much .
# 4  
Old 01-10-2010
Hello Ravi.

You would have to add another condition to check if both are equal. Always think of if else statements as branches of a tree. If condition A is true then follow branch A , else if condition B is true follow branch B else(the last option) follow some default branch.

Code:
#!/bin/bash
echo "enter two nos"
read a b
if [ $a -gt $b ]
then
        echo $a is greater
elif [ $b -gt $a ]
then
        echo $b is greater
else
        echo both are equal
fi

hope you get the idea.
Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Error in excuting while loop

can you please support me to understand what is wrong in this code, I am getting error as sytnax error near unexpected token if if then code is cat text.txt | /path/mapper.sh data in file is hi hi how how are you while read line do for word in $line do if then wcount=`echo... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

Not getting colorcode when excuting html in UNIX

Hi i have below code which i am running and the out i want should be in red color echo "<html>" >> ERROR_FILE.html echo "<Body>" >> ERROR_FILE.html nawk 'BEGIN{print "<table border="1">"} {print "<tr>"; print "<TD colspan="0" bgcolor="#DC143C">"; for(i=1;i<NF;i++)... (5 Replies)
Discussion started by: mirwasim
5 Replies

3. UNIX for Dummies Questions & Answers

Crontab jobs excuting

Hi i want to run the cronjob from 7 Am till 11.30Am for every 5 minutes from monday to friday. can anyone help? (15 Replies)
Discussion started by: satheesh_charle
15 Replies

4. Shell Programming and Scripting

Excuting perl script from within a perl script with variables.

Not sure what I am doing wrong here, but I can print the list with no issue. Just a blank screen with the 'do'. #!/usr/bin/perl open FILE, "upslist.txt"; while ($line=<FILE>){ if ($line=~/^(.*?),(.*?)$/){ #print "ups:$1 string:$2\n"; do 'check_snmp_mgeups-0.1.pl -H $1 -C $2'; } ... (1 Reply)
Discussion started by: mrlayance
1 Replies

5. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

6. Shell Programming and Scripting

excuting the following code

hi i am trying the below code for the following |_ | |_ | |_ |_ | |_ |_ |_ | |_ |_ |_ |_ and for this code also * * * * * * * * * * * * * * * !/bin/bash #i = "*" (2 Replies)
Discussion started by: kullu
2 Replies

7. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

8. AIX

crontab isn't excuting some commands

Greetings everybody, I have an IBM P520 AIX 5.3 server machine and trying to use crontab to periodically excute a script that contains a command belongs to my software (Fast/Tools SCADA software) I added the following line after using crontab -e 01 * * * * /mypath/myscript I have two... (3 Replies)
Discussion started by: ayman metwally
3 Replies

9. UNIX for Dummies Questions & Answers

Excuting Multiple shell files in sequesnce

Hi, I have two shell scripts each executing a java process independently. These are two independent processes and I need to sequence them using another shell script. What I did was created another shell script and called these independent shell scripts in it. It runs fine, however from time... (3 Replies)
Discussion started by: gupta_arunesh
3 Replies

10. UNIX for Dummies Questions & Answers

excuting a shell script within ftp script

Novice here... I need help with excuting a shell script on a flat file that I've transfered over from a Windows XP machine for manipulation through an auto FTP script... so that after it is transfers it excutes the shell script and then returns it back to XP machine... Any ideas... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question