Reputation: 13
So I want to know if a given path exists (may not necessarily be a directory.) I know that you can test if a directory exists with [ -d "$arg" ]
, but I want to know how to test if any path exists, not whether it is a directory. Can someone point me in the direction to where to look.
Upvotes: 0
Views: 75
Reputation: 50750
That's what -e
primary does (except for symlinks though, test
builtin follows symbolic links and operate on the target of the link, rather than the link itself).
[ -e "$arg" ]
An alternative that works with symlinks as well (requires GNU find):
find "$arg" -quit 2>/dev/null
Upvotes: 1
Reputation: 7277
You can do that with ls
ls $path &> /dev/null && echo 'yep' || echo 'nop'
Upvotes: 0