I know that some shells at least support file test operators that detect when a filename names a symlink.
Is there a POSIX utility1 that provides the same functionality?
1 I may not be using the right terminology here. What I mean by "utility" is a free-standing executable living somewhere under /bin
, /usr/bin
, etc., as opposed to a shell built-in.
Best Answer
You're looking for
test
:Most shells have it as a builtin, but
test
also exists as a standalone program, which can be called from other programs without invoking an intermediate shell. This is the case for most builtins that shells may have, except for those that act on the shell itself (special builtins likebreak
,export
,set
, …).[ -h pathname ]
is equivalent totest -h pathname
;[
works in exactly the same way astest
, except that[
requires an extra]
argument at the end.[
, liketest
, exists as a standalone program.For example: