Obviously I know about
readlink, but is there a command to find out the real absolute path to the current directory (ie, resolving links and dots)?
(in any POSIX shell), is the command you're looking for.
-P is for physical (as opposed to logical (
-L, the default) where
pwd mostly dumps the content of
$PWD (which the shell maintains based on the arguments you give to
$ ln -s . /tmp/here $ cd /tmp/here/here $ cd ../here/here $ pwd /tmp/here/here/here $ pwd -P /tmp
$ env pwd
Unless the variable POSIXLY_CORRECT is set, in which case you need to add
The shell has a builtin called
pwd which defaults to printing the value of shell's
$PWD. In doing so, it may include logical paths (a default
If you call the builtin with (
-P) or use the external
$ ln -s . /tmp/here; cd /tmp/here/here/here $ pwd /tmp/here/here/here $ pwd -P /tmp $ /bin/pwd /tmp
The reason is that the external
/bin/pwd defaults to the
this implementation uses
-P' as the default unless thePOSIXLY_CORRECT' environment variable is set.