While loop problem

I have a while loop with -f and -o option.Can any one please tell me what that stands for?The Sample code is as follows:-

while [ ! -f $DATA/$AMPS_COMPLETE01 -o ! -f $DATA/$AMPS_COMPLETE02 -o \
! -f $DATA/$AMPS_COMPLETE03 -o ! -f $DATA/$AMPS_COMPLETE04 -o \
$PMON_COUNT -eq 0 ] 
do
  ## some processing
done

You could find that out by reading the man page for test(1).

-f file       True if file exists and is a regular file

expression1 -o expression2
                   True if either expression1 or expression2 are true.

! negates the test (meaning "if not ...").

Thanks for the reply.I got the information from the man page ,but still one more doubt was "what the back slash is used for in the code".

It is a line-continuation character, allowing you to span commands over multiple lines. This is usually done to aid readability.

Hi Scottn,

Thanks for ur explanation btw, even I made quite many shell scripts(just simple scripts I think), but never know we can continue line by using \

Gotta try it tomorrow

Thanks Param0073 for asking this :smiley:

Backslashes are used to escape the following character.. So when you backslash, and then hit enter, it is not interpreted as a request for the shell to execute the preceding code, only to go to the next line and continue.. You could use this to do longer scripts in the shell instead of just one liners.

That's how I understand it at least.

Just like when you have spaces in a path, instead of quotes, you can escape them like : ~/My\ Directory/files/work\ stuff/Superchams.sh

You can also use an until statement, which may make it a bit more readable (also -o and -a are deprecated):

until [ -f $DATA/$AMPS_COMPLETE01 ] && [ -f $DATA/$AMPS_COMPLETE02 ] && \
      [ -f $DATA/$AMPS_COMPLETE03 ] && [ -f $DATA/$AMPS_COMPLETE04 ] && \
      [ $PMON_COUNT -ne 0 ] 
do

Isn't && logical AND? Wasn't the poster using -o which is Logical Or?

Shouldn't it then be:

until [ -f $DATA/$AMPS_COMPLETE01 ] || [ -f  $DATA/$AMPS_COMPLETE02 ] || \
      [ -f $DATA/$AMPS_COMPLETE03 ] || [ -f  $DATA/$AMPS_COMPLETE04 ] || \
      [ $PMON_COUNT -ne 0 ] 
do

In:

I do try to stay current, but I must have missed this. Can you provided me with a reference to this deprecation?

I used until instead of while which inverts the condition

---------- Post updated at 21:13 ---------- Previous update was at 21:11 ----------

Hi, this is in the latest POSIX specification: test: APPLICATION USAGE

[quote=scrutinizer;302484078]
I used until instead of while which inverts the condition

Wow, I didn't know or think of that! Darn, I thought I had you! :slight_smile: