* conditional expressions (incompatible with ksh)
@ 2001-10-10 17:35 lists
2001-10-10 17:44 ` Will Yardley
2001-10-10 19:15 ` Clint Adams
0 siblings, 2 replies; 4+ messages in thread
From: lists @ 2001-10-10 17:35 UTC (permalink / raw)
To: zsh-users
Hello,
So I have a ksh script which tests to see if a file exists like so:
if [ -a file ]; then
This works correctly in both ksh and bash. However, in zsh (both the normal
mode, and the ksh compatible mode), the -a operator is only interpreted
as boolean AND, never as "file exists" in the appropriate context.
According to my "Unix in a Nutshell" book, -a is used for both operators,
and the shell needs to determine the correct use from context.
I realize that I could use [[ ]] instead of [ ] to work around this problem,
but the script needs to remain compatible with other shells, so this isn't
really a good option.
Any idea what the correct behavior should be?
mdr
--
Matthew D. Rench
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: conditional expressions (incompatible with ksh)
2001-10-10 17:35 conditional expressions (incompatible with ksh) lists
@ 2001-10-10 17:44 ` Will Yardley
2001-10-10 19:15 ` Clint Adams
1 sibling, 0 replies; 4+ messages in thread
From: Will Yardley @ 2001-10-10 17:44 UTC (permalink / raw)
To: zsh-users
lists@pelennor.net wrote:
> So I have a ksh script which tests to see if a file exists like so:
>
> if [ -a file ]; then
> This works correctly in both ksh and bash. However, in zsh (both the
> normal mode, and the ksh compatible mode), the -a operator is only
> interpreted as boolean AND, never as "file exists" in the appropriate
> context.
perhaps someone can give a more detailed answer, but the '-a' operator
isn't mentioned in my bash scripting book, and i've never seen this
operator used (although i'll admit it works in bash and not in zsh).
how about using instead....
-e file exists
-f file exists and is a regular file (ie not a directory)
-s file exists and is not empty
i'd guess -f or -e is probably what you want and should work in bash,
ksh and zsh.
w
--
GPG Public Key:
http://infinitejazz.net/will/pgp/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: conditional expressions (incompatible with ksh)
2001-10-10 17:35 conditional expressions (incompatible with ksh) lists
2001-10-10 17:44 ` Will Yardley
@ 2001-10-10 19:15 ` Clint Adams
2001-10-10 19:16 ` please take me off of this mailing list Matthew Peter Lyon
1 sibling, 1 reply; 4+ messages in thread
From: Clint Adams @ 2001-10-10 19:15 UTC (permalink / raw)
To: lists; +Cc: zsh-users
> Any idea what the correct behavior should be?
The POSIX-correct behavior should be to produce
unspecified results, since -a as a unary primary
is a bashism/kshism and not POSIX-compliant.
Use -e instead.
^ permalink raw reply [flat|nested] 4+ messages in thread
* please take me off of this mailing list.
2001-10-10 19:15 ` Clint Adams
@ 2001-10-10 19:16 ` Matthew Peter Lyon
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Peter Lyon @ 2001-10-10 19:16 UTC (permalink / raw)
To: lists; +Cc: zsh-users
please take me off of this mailing list.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-10-10 19:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-10 17:35 conditional expressions (incompatible with ksh) lists
2001-10-10 17:44 ` Will Yardley
2001-10-10 19:15 ` Clint Adams
2001-10-10 19:16 ` please take me off of this mailing list Matthew Peter Lyon
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).