BASH BUILTIN -E AND SYMLINKS
2015 January 26Just a quick reminder that bashs builtin -e test returns false for symlinks whose destination doesn’t exist:
[11:11:52][blindcoder@flora:~]$ bash --version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[11:11:59][blindcoder@flora:~]$ ln -s /nonexistant
[11:12:04][blindcoder@flora:~]$ ls -l nonexistant
lrwxrwxrwx 1 blindcoder blindcoder 12 Jan 26 11:12 nonexistant -> /nonexistant
[11:12:07][blindcoder@flora:~]$ if [ -e nonexistant ]; then
> echo "Symlink nonexistant exists and points to $( readlink nonexistant )"
> else
> echo "Symlink nonexistant does not exist"
> fi
Symlink nonexistant does not exist
[11:12:43][blindcoder@flora:~]$
EOF
Category: blog