0

I'm confused on one of the ksh93 test qualifiers that we use. Twenty+ years ago we took a "Unix Shell Programming - featuring the KornShell" course. In the manual that accompanied that course it says that "-a filename" will be successful if the file exists. We've used "-a" extensively since that time. I recently came across this link that says "-a" is a 'binary AND operator' for testing (we are using ksh93 on AIX 7.1), and 'man test' shows the same output as the link.

https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.cmds5/test.htm

Now that link seems to be a general AIX link. That is, it's not obvious to me that it's specific to ksh, csh, sh, etc, so I'm not sure how it applies.

It does appear that our existing code works as expected. Here's an example of how we currently use it.

if [[ -a filename ]]
then
    ....
fi

I realize that there are other qualifiers for testing files, but I'm wondering why "-a" seems to check for existence while the manpage suggests it doesn't.

Thanks in advance.

2

From the ksh manual:

   Conditional Expressions.
       A  conditional  expression  is  used with the [[ compound command to test attributes of files and to
       compare strings.  Field splitting and file name generation are not performed on the words between [[
       and  ]].   Each  expression  can  be  constructed  from one or more of the following unary or binary
       expressions:
       string True, if string is not null.
       -a file
              Same as -e below.  This is obsolete.
       -e file
              True, if file exists.
| improve this answer | |
  • Thanks to both of you. Where does one get an online ksh manual, specifically ksh93 as implemented on AIX. Does such a thing exist? – Scavenger Jan 8 '18 at 19:04
  • There's a poor one here or here or here; "poor" = not fully documented, but better than the manpage on the systems themselves. – Jeff Schaller Jan 8 '18 at 19:41
  • I guess get a ksh manual then make mental notes of the items in the enhanced korn shell link you provided. – Scavenger Jan 8 '18 at 20:02
  • 1
    man ksh on any system with the shell (properly) installed will open the manual page for ksh in your preferred pager (e. g. less). – DopeGhoti Jan 8 '18 at 20:06
1

The binary test (or [) that exists in PATH is not the same as [[ which may be a shell builtin; for [[ consult instead the shell's documentation. If you call test or [ you may actually be calling a shell builtin and not the binary, depending on the shell. The following is not AIX nor its KSH, but rather the heirloom bourne shell or mksh on Mac OS X where sh does not support either the [[ or -a exists flag, but mksh does:

$ sh
$ [[ -a /etc/passwd ]] && echo yea
[[: not found
$ [ -a /etc/passwd ] && echo yea
test: argument expected
$ exit
$ [[ -a /etc/passwd ]] && echo yea
yea
$ [ -a /etc/passwd ] && echo yea
yea
$ 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.