Re: The "-e" test ingores broken links

2016-10-15 Thread Stephane Chazelas
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




Re: The "-e" test ingores broken links

2016-10-13 Thread 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."

Peter

On 14/10/2559 02:00, Łukasz Grabowski wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: i586
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CON
> FIG_H   -I.  -I../. -I.././include -I.././lib  -D_FORTIFY_SOURCE=2 -g
> -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall
> uname output: Linux brutus 3.16.0-4-686-pae #1 SMP Debian
> 3.16.36-1+deb8u1 (2016-09-03) i686 GNU/Linux
> Machine Type: i586-pc-linux-gnu
> 
> Bash Version: 4.3
> Patch Level: 30
> Release Status: release
> 
> Description:
> according to docs -e test should return true when tested on files,
> including broken links, but it doesn't
> 
> Repeat-By:
> the two commands
> ln -s xxx a
> if [ -e a ]; then echo "exists!"; fi
> don't produce any output on my system
> 
> 
> Best,
> Łukasz Grabowski
> 




The "-e" test ingores broken links

2016-10-13 Thread Łukasz Grabowski
Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CON
FIG_H   -I.  -I../. -I.././include -I.././lib  -D_FORTIFY_SOURCE=2 -g
-O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall
uname output: Linux brutus 3.16.0-4-686-pae #1 SMP Debian
3.16.36-1+deb8u1 (2016-09-03) i686 GNU/Linux
Machine Type: i586-pc-linux-gnu

Bash Version: 4.3
Patch Level: 30
Release Status: release

Description:
according to docs -e test should return true when tested on files,
including broken links, but it doesn't

Repeat-By:
the two commands
ln -s xxx a
if [ -e a ]; then echo "exists!"; fi
don't produce any output on my system


Best,
Łukasz Grabowski