Simple program but problem-pls Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple program but problem-pls Help
# 1  
Old 07-08-2008
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  
Old 07-08-2008
Code:
#!/usr/bin/sh

value1=90;
value2=70;
if [ $value1 -gt $value2 ];
then
echo "$value1 is normal"
else
echo "$value2 is abnormal"
fi

# 3  
Old 07-08-2008
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 Smilie

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  
Old 07-08-2008
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  
Old 07-08-2008
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  
Old 07-08-2008
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  
Old 07-08-2008
Quote:
Originally Posted by user__user3110
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

A simple C program query ...

Given the following code inside the function ext3_write_super(): (It's there in Linux kernel 2.6.27.59) static void ext3_write_super (struct super_block * sb) { if (mutex_trylock(&sb->s_lock) != 0) BUG(); sb->s_dirt = 0; } The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies

2. UNIX for Dummies Questions & Answers

Help with creating a simple program!!

i am new to shell scripting!! i am making this program in bourne shell, that asks the user to input "Hello (their name)" or "question (their name)", any other input, "ERROR" will be outputted. if they input "Hello (name)", i want to out saying Hello (name) but if they input "question (name)", i... (4 Replies)
Discussion started by: bshell_1214
4 Replies

3. Shell Programming and Scripting

Help with simple program. (beginner)

Hey all, Writing a program that searches for a username and if they are online creates a 'beep' and sends the username and date to a log file. the error i am getting is: paul.obrien16@aisling:~/os$ bash checklogin : command not found Enter username paul.obrien16 ': not a valid... (2 Replies)
Discussion started by: sexyladywall
2 Replies

4. Shell Programming and Scripting

Shell program help pls

first queestion if what does "-s" mean? second seqx -n 10000000 -c 10 < $seqfile >$temp seqx? -n? -c? what do these mean? third if && ! cmp -s $missing $temp explain these codes ty (2 Replies)
Discussion started by: imtheone
2 Replies

5. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

6. Programming

Xlib simple program.

I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages. I have tried and tried,but never get past Hello World. Can someone help me please? ---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
Discussion started by: megane16v
2 Replies

7. Shell Programming and Scripting

Problem.. can someone pls help..

Hi All, My file contains data like below. Key ~PILCSZY First Name Szymon Surname Pilch User Code Group SCO-PL User Group Description SCO - Poland Key ... (2 Replies)
Discussion started by: harshakusam
2 Replies

8. Programming

a simple chat program

any suggestions on how i could create a simple chat program between two terminals using pipes? thanks (1 Reply)
Discussion started by: kelogs1347
1 Replies

9. Shell Programming and Scripting

HELP me PLS... Simple Scripting!

this is my script.... SQL> select * from dba_profiles 2 where resource_name in ('FAILED_LOGIN_ATTEMPTS','PASSWORD_LOCK_TIME') 3 order by profile; and this is the output... PROFILE RESOURCE_NAME RESOURCE... (2 Replies)
Discussion started by: liezer
2 Replies

10. Programming

QUESTION...simple program?

I am new to the unix/linux environment. AND........ I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!! (8 Replies)
Discussion started by: jj1814
8 Replies
Login or Register to Ask a Question