testing if a file is present

Wm E. Davidsen Jr davidsen at sixhub.UUCP
Fri Nov 23 14:07:29 AEST 1990


In article <1990Nov21.191638.19469 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:

| In sh, with either a test built-in named "[" or a link in your filesystem
| called "[" pointing to the test program:
| 
| 	if [ -r filename ]; then
| 		... stuff if filename exists ...
| 	fi
| 
| Some versions of test allow "-e" to test for existence, instead of "-r" to
| test for existence and readibility, but mine doesn't, so I use "-r" instead of
| "-e" above.  In sh without "[":
| 
| 	if test -r filename; then
| 		... stuff if filename exists
| 	fi

  Close but not correct.
	-f is there a file
	-r is it readable
	-x is it executable
-- 
bill davidsen - davidsen at sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.shell mailing list