bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The "-e" test ingores broken links


From: Stephane Chazelas
Subject: Re: The "-e" test ingores broken links
Date: Fri, 14 Oct 2016 22:01:49 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2016-10-14 07:08:22 +0700, Peter & Kelly Passchier:
> WHich docs?
> If I do "help test" it states: "All file operators except -h and -L are
> acting on the target of a symbolic link, not on the symlink itself, if
> FILE is a symbolic link."
[...]

Yes, to test for file existence, the syntax is

[ -e "$file" ] || [ -L "$file" ]

Or:

ls -d -- "$file" > /dev/null 2>&1

But even then, if it returns false, that doesn't necessarily
mean the file doesn't exist. It could also be that it's
impossible to tell. If you remove the 2>&1 above, the error
message would help you differentiate between the cases.

If using zsh instead of bash, you can also check the $ERRNO
variable to see if [ -e ] failed because of ENOENT or something
else.

See also 
https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash/40046642#40046642

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]