From: Bill Thompson (bill.thompson@GOODYEAR.COM)
Date: Fri Jul 19 2002 - 11:30:30 EDT
My understanding of the file attribute operators from page 131 of
O'Reilly's Learning the Korn Shell was that they applied to internal Korn
shell evaluations which are accessed by using the double square brackets
([[]]).
According to page 126 when you use the single square brackets ([]) you are
calling the external command /bin/test (this can be easily proved):
unset A
if [[ -z $A ]]; then print true; fi
true
if [ -z $A ]; then print true; fi
ksh: test: 0403-004 Specify a parameter with this command.
Notice the error comes from "test".
The man page for test says "-a Binary AND operator". There is nothing in
the test man page for a simple "file exists".
My confusion is the code in question uses the single brackets for the
evaluation therefore the -a should be interpreted as a binary AND, not a
"file exists".
Is this an undocumented feature of test?
Bill Thompson
Sr UNIX Systems Administrator
The Goodyear Tire & Rubber Co.
Contains Confidential and/or Proprietary Information
May Not Be Copied or Disseminated Without Express Consent of The Goodyear
Tire & Rubber Company.
AIX-L Archives: http://marc.theaimsgroup.com/?l=aix-;&r=1&w=2
----- Original Message -----
From: Steve Thornhill
Newsgroups: bit.listserv.aix-l
To: aix-l@Princeton.EDU
Sent: Friday, July 19, 2002 10:09 AM
Subject: Re: Off Topic Scripting Question
Excerpt from page 131 of O'reilly's Learning the Korn Shell
Operator True if...
-a file file exists
-d file file is a directory
-f file file is a regular file (i.e., not a directory or other special
type of file)
-r file You have read permission on file
-s file file exists and is not empty
-w file You have write permission on file
..... + a few more.
Any help?
Steve Thornhill - IBM CLS
Int - 255104
Ext - 023 92 565104
Mob - 07778 289770
Email/Sametime - steve_thornhill@uk.ibm.com
Bill Thompson <bill.thompson@GOODYEAR.COM>
Bill Thompson
<bill.thompson@GOODYEAR.CO To:
M> aix-l@Princeton.ED
Sent by: IBM AIX U
Discussion List cc:
<aix-l@Princeton.EDU> Subject: Off Topic
Scripting Question
19/07/2002 14:38
Please respond to IBM AIX
Discussion List
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