if loop problem in bourne shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if loop problem in bourne shell
# 1  
Old 09-18-2008
if loop problem in bourne shell

how to use if-loop in bourne shell with multiple conditions like follows

if [ a > b && c > d ]
then
commands
fi

it gives me an error

test: ] missing

then i put
if [[ a > b && c > d ]]
it gives me an error
[[ not found

kindly i need the syntex for the bourne shell
# 2  
Old 09-18-2008
Have you tried
Code:
if [ a > b ] && [ c > d ]

# 3  
Old 09-18-2008
You must have an ancient version -
Code:
if [ $a -gt $b ] ; then
   if [ $c -gt $d ] ; then
   fi
fi

is what you will have to use.
# 4  
Old 09-18-2008
Tools Does the following example help you?

The first example executes to TRUE, and prints "greater". The second example is FALSE, and nothing prints

Code:
> if [ 14 -gt 13  -a  15 -gt 12 ] ; then echo "greater"; fi
greater

> if [ 4 -gt 13  -a  5 -gt 12 ] ; then echo "greater"; fi

# 5  
Old 09-18-2008
Quote:
You must have an ancient version -
Seems I wasn't paying attention to the argument - just the format! Thanks Jim Smilie

This is what it could look like:
Code:
if [ $a -gt $b ] && [ $c -gt $d ]

# 6  
Old 09-20-2008
if loop problem in bourne shell

Thanks a lot guys , all the syntax worked fine except this one

if [ a > b ] && [ c > d ]

...thanks again Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For loop in bourne shell is not working

I have a loop with cases I am working on Bourne shell for file in *.${Today}*.csv *.${Today}*.txt\ do case ${file} in sun_detail) do something ;; sum) do something ;; mod) do something ;; *) do something ;; (5 Replies)
Discussion started by: digioleg54
5 Replies

2. Shell Programming and Scripting

Confusion about FOR LOOP syntax between Bourne and BASH shell. Please see.

for (( i=1; i<=3; i++ )); do for (( j=1; j<=3; j++ )); do for (( k=1; k<=3; k++ )); do echo $i$j$k done done done Will the above code work on a BOURNE shell? As far as my understanding is, if I am writing the above code in a file..say lol.sh and then running it through the terminal using... (7 Replies)
Discussion started by: navienavnav
7 Replies

3. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

4. Shell Programming and Scripting

loop problem in c shell

Hi all, i got problem with this statement. I use 2 time loop while in 1 statement . But it excetu at second loop while. I want it continue loop until it stop when wrong. Plz help me -- #!/bin/csh set app_dir = "/ebsxe/ebs25/users/mmlim/assignment01" set line_array = (`cat... (0 Replies)
Discussion started by: proghack
0 Replies

5. Shell Programming and Scripting

while loop problem in c shell script

Hi all, i write a script c shell set i = 1 while ( $i <= $#array ) echo "$array" @ i++ end i want to set it to i = i +2 in that statement . Can anybody help me? ---------- Post updated at 02:46 PM ---------- Previous update was at 02:35 PM ---------- anybody not how to solve it??? (2 Replies)
Discussion started by: proghack
2 Replies

6. Shell Programming and Scripting

Help on "for" loop in bourne shell

Hello Everyone.... I am trying to print a number sequence in following format using for loop. I am using a bourne shell. I tried following for loop condition but it is bash syntax. for (( i=0; i<=5; i++ )) It is giving syntax error. Kindly help with the syntax of "for"... (7 Replies)
Discussion started by: EmbedUX
7 Replies

7. Shell Programming and Scripting

Problem with while loop in shell script

Hi All, How to read a file upto last line(End Of Line) I wrote below program: cat R2_20060719.610.txt | while read LINE do echo "$LINE" done above code reading all lines from a file and skipping last line...... is there anything wrong in my code. Please help me out from this... (20 Replies)
Discussion started by: rkrgarlapati
20 Replies

8. Shell Programming and Scripting

problem with while loop in BASH shell

I have file named script1 as follows: #!/bin/bash count="0" echo "hello" echo "$count" while do echo "$count" count=`expr $count + 1` done ----------- when I run it, I get ./script1: line 9: syntax error near unexpected token `done' ./script1: line 9: `done' I... (6 Replies)
Discussion started by: npatwardhan
6 Replies

9. Shell Programming and Scripting

for loop problem in K shell

I want to echo from 1 to 100 using a for loop. I was trying out all possible syntax using for loop, but it errors out. can you help me in doing this? I was using for i in 1..100 do echo $i done Regards Asutoshch (4 Replies)
Discussion started by: asutoshch
4 Replies

10. Shell Programming and Scripting

Shell Script loop problem

I am writing a shell script that simulates the `wc -w` command without actually using wc itself. My problem is that the script will only read the first line of the file and just keep looping through it. I have tried both while and for loops and got the same result. Can anyone help? ... (1 Reply)
Discussion started by: MaxMouse
1 Replies
Login or Register to Ask a Question