while loop in /bin/sh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers while loop in /bin/sh
# 1  
Old 03-11-2009
while loop in /bin/sh

Hi!

I want my script to enter in a while cicle. And I did a:

var=0

while [$var < 1]
do
echo "while"
done

this is very simple because it's just for testing

So what I think that was suppost to happen was
while
while
while
while
while
while
....
....
while

BUT nothing

what is wrong in my while

thanks
# 2  
Old 03-11-2009
Try changing the < operator:

Code:
while [ "$var" -lt 1 ]
do
  echo "while"
done

# 3  
Old 03-11-2009
Quote:
Originally Posted by radoulov
Try changing the < operator:

Code:
while [ "$var" -lt 1 ]
do
  echo "while"
done

thanks, it works but not in my script because it says line 29 [0: not found (????)
so my code is:


Quote:
#!/bin/sh

var=0
echo $var
LOGFILE=`mktemp -t svn_checkout.XXXXXX`
ICONPATH="`dirname $0`/svn.xpm"
list=`ssh ruben@192.168.1.3 "ls /esp-server/svn"`
URL=`zenity --entry --title="Subversion: Checkout" --text="$list

Enter repository folder according to the the aboves:" --entry-text="" --width=400 --window-icon="$ICONPATH" 2>&1`

if [ $? -eq 0 ] ; then
svn checkout svn+ssh://ruben@192.168.1.3/esp-server/svn/$URL &> $LOGFILE & pid1=$!
echo $pid1
zenity --progress --pulsate --auto-kill & pid2=$!
echo $pid2
DIR=/proc/$pid1
echo $DIR
while [$var -lt 1]
do
echo "while"
if [ -d $DIR ] ; then
echo "does exist"
else
echo "does not exist"
fi
done
rm -f $LOGFILE
fi
echo "end"
and my line 29 is the last fi. And I have a lot of echo to show me the status.
Now I realy don't know why it doesn't enter in the while
Can you help me??

thanks
# 4  
Old 03-11-2009
Change this:

Code:
[$var -lt 1]

to this

Code:
[ $var -lt 1 ]

You need a space after the opening bracket and another one before the closing one.
# 5  
Old 03-11-2009
Quote:
Originally Posted by radoulov
Change this:

Code:
[$var -lt 1]

to this

Code:
[ $var -lt 1 ]

You need a space after the opening bracket and another one before the closing one.

MANNNNNN no way. lol I lost sooooo many time and was just a space. lol

thanks
# 6  
Old 03-11-2009
other thing
here:
if [ -d $DIR ] ; then

how can I use a not
like -d $DIR but negative
# 7  
Old 03-11-2009
Code:
[ ! -d "$DIR" ]

or

Code:
[ -d "$DIR" ] || ...

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

2. AIX

Redistribution bin required for AIX. j7r164redist.7.1.0.25.bin

Hi, I am planning to install a version of Informatica on my AIX box. It requires a specific java build in pap6470_27sr2-20141101_01(SR2). The current link for IBM 64-bit SDK for AIX®, JavaTM Technology Edition, Version 7 Release 1 has a more recent version in j7r164redist.7.1.0.75.bin. Is... (4 Replies)
Discussion started by: meetpraveens
4 Replies

3. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

4. Solaris

What is the difference between xpg4/bin and usr/bin?

Hi Experts, I found that the same commands(sort, du, df, find, grep etc.) exists in both dir. What is the difference to use them? i.e: to use xpg4/bin/grep and usr/bin/grep My OS version is SunOS 5.10 Regards, Saps (7 Replies)
Discussion started by: saps19
7 Replies

5. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

6. UNIX for Dummies Questions & Answers

Alias /usr/bin to /bin in profile

Hi! All the basic linux commands, ie. echo, find, etc, are located in /bin. I have a couple of programs that have these commands pointed towards /usr/bin, ie, /usr/bin/echo (even though the actual 'echo' command is in /bin). How can I alias or redirect or link the /usr/bin to /bin just for this... (6 Replies)
Discussion started by: dancerat
6 Replies

7. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

8. Shell Programming and Scripting

Why does my /bin/csh take longer than /bin/perl?

Okay, so I have two "Hello, world!" scripts, "test.pl" and "test.sh". #!/bin/perl -w use strict; print "Hello, world!\n"; #!/bin/csh echo Hello,\ world! When I run test.pl, it runs instantly, always. When I run test.sh, it takes anywhere between 4 and 22 seconds! I'd like to know what... (3 Replies)
Discussion started by: acheong87
3 Replies

9. UNIX for Dummies Questions & Answers

Difference between /bin, /usr/bin, /sbin ?

Hi All, Can somebody tell me the difference between /bin, /usr/bin, /sbin ? Thanx in advance, Saneesh Joseph (3 Replies)
Discussion started by: saneeshjose
3 Replies

10. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question