Off Topic Scripting Question

From: Bill Thompson (bill.thompson@GOODYEAR.COM)
Date: Fri Jul 19 2002 - 09:38:42 EDT


This is a Borne/Korn shell question which is not AIX specific. Sorry if
it's somewhat off topic.

I was reviewing an old script and found the following conditional:

if [ -a $filename ]; then ...

My immediate reaction is that the -a should have been a -f

While the -f is probably the more appropriate test, I did some
experimenting at the command line...

if [ -a ]; then echo true; else echo false; fi
true

if [ -a .profile ]; then echo true; else echo false; fi
true

if [ -a not_a_file ]; then echo true; else echo false; fi
false

-a is the binary AND which is typically used between two conditionals like
this:
    if [ $A -lt $B -a $C = "OK" ]; then ...

Assuming the contents of "$filename" is the name of a file (or directory),
can somebody explain why "if [ -a $filename ]" returns TRUE if the file
exists and FALSE if the file does not exist?

BTW:
if [ .profile ] or if [ not_a_file ] both return TRUE (which is what I
would expect because the strings are not null).

TIA

Bill Thompson
The Goodyear Tire & Rubber Company
Contains Confidential and/or Proprietary Information.
May Not Be Copied or Disseminated Without Express Consent of The Goodyear
Tire & Rubber Company.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:04 EDT