The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple date problem ali560045 Shell Programming and Scripting 4 01-22-2008 02:12 AM
a simple chat program kelogs1347 High Level Programming 1 12-07-2006 07:59 AM
Simple Network Program Difficulties Mistwolf High Level Programming 2 03-19-2002 06:34 AM
may be simple but i don't know -- Print current date from C program ls1429 High Level Programming 6 02-19-2002 01:50 AM
QUESTION...simple program? jj1814 High Level Programming 8 02-07-2002 01:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-08-2008
user__user3110 user__user3110 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 18
Simple program but problem-pls Help

Hi All,
I have problem in the following shell script (problem in 2and3 line i guess)
#!/bin/sh
set value1 = 90;
set value2 = 70;
if [ $value1 > $value2 ]; then
echo "$value1 is normal"
else
echo "$value2 is abnormal"
fi


when executed
output:
$ value_test.sh (Enter)
is abnormal

Neither it's printing the $value1,nor it's displaying correct output.but no errors.
It is not atall executing the loop properly and jumps to else directly.

I guess the problem is with Set value command..
i guess it's wrong.... pls let me know the correct command.

Thanks
  #2 (permalink)  
Old 07-08-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Code:

#!/usr/bin/sh

value1=90;
value2=70;
if [ $value1 -gt $value2 ];
then
echo "$value1 is normal"
else
echo "$value2 is abnormal"
fi
  #3 (permalink)  
Old 07-08-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
Btw: There is no need to have semicolons at the end of variable declaration in bash and there is a [ C O D E ] tag to put code into a box so you don't have to mark it red

Just as namishtiwari wrote, or define the values as integer and you can got with arithmetic signs (else it will think you might want to redirect an output):
Code:
#!/bin/sh
typeset -i value1=90
typeset -i value2=70
if [ $value1 > $value2 ]; then
   echo "$value1 is normal"
else
   echo "$value2 is abnormal"
fi
  #4 (permalink)  
Old 07-08-2008
user__user3110 user__user3110 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 18
Hi zaxxon and namishtiwari thanks for your quick turn over,

For namishtiwari
If I edit code as per u say… im getting the following output:
$ value_test.sh
Is normal.

Here it’s executing the loop successfully nut it’s not displaying $value1 value
The out put should be like this right…
$ value_test.sh
90 Is normal.

Please see $value is missing.

For zaxxon,
If u edit code as per u say…
Im getting the following error…
$ value_test.sh
value_test.sh: typeset: not found
value_test.sh: typeset: not found
is normal

But here also it’s executing the loop.

Please help me.

Thanks
  #5 (permalink)  
Old 07-08-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
Strange you dont have typeset... nvm, try this:

Code:
root@isau02:/data/tmp/testfeld> ./mach.sh
90 is normal
root@isau02:/data/tmp/testfeld> cat mach.sh
#!/bin/sh

value1=90
value2=70

if (( ${value1} > ${value2} )); then
        echo "${value1} is normal"
else
        echo "${value2} is abnormal"
fi
  #6 (permalink)  
Old 07-08-2008
user__user3110 user__user3110 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 18
Hi Zaxxon,
Still im not getting the desired output..
here is the code
#!/bin/sh
value1=90
value2=70
if (( ${value1} > ${value2})); then
echo "${value1} is normal"
else
echo "${value2} is abnormal"
fi


and output:
$ ./value_test.sh
./value_test.sh: 90: not found
70 is abnormal


I DONT KNOW WATS WRONG...
PLSSSSSSS HELP.

THANKS
  #7 (permalink)  
Old 07-08-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by user__user3110 View Post
Hi zaxxon and namishtiwari thanks for your quick turn over,

For namishtiwari
If I edit code as per u say… im getting the following output:
$ value_test.sh
Is normal.

Here it’s executing the loop successfully nut it’s not displaying $value1 value
The out put should be like this right…
$ value_test.sh
90 Is normal.

Please see $value is missing.

For zaxxon,
If u edit code as per u say…
Im getting the following error…
$ value_test.sh
value_test.sh: typeset: not found
value_test.sh: typeset: not found
is normal

But here also it’s executing the loop.

Please help me.

Thanks
I am getting the right output as you are saying see this--

namish@france => ./sample1
90 is normal

No need to edit anything just copy the code.

Thanks
namish
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0