Realpath output includes the input
You gave realpath
a relative path, to a file in the current directory.
The file (which may be a directory) may or may not exist. realpath
does not care by default. It reports the path regardless of whether its last element exists.
If you want it to only report paths that exist, use the -e
flag:
zanna@toaster:~/playground$ realpath playground
/home/zanna/playground/playground
zanna@toaster:~/playground$ realpath ~/playground
/home/zanna/playground
zanna@toaster:~/playground$ realpath -e playground
realpath: playground: No such file or directory
That's because you're giving it a path that doesn't exist, so it simply prints out the current directory and whatever you gave it, assuming that would be the path. Note that the man page specifies that:
Print the resolved absolute file name; all but the last component must exist
So it allows execution with a nonexistent target. To illustrate, consider these examples:
$ pwd
/home
$ ls
lost+found terdon
$ realpath terdon
/home/terdon
$ realpath nonExistentDir
/home/nonExistentDir
Or, to duplicate what you did:
$ pwd
/home/terdon
$ realpath terdon
/home/terdon/terdon
No, it only tells you that the path to the (probably non-existent) file yosefkl
located in the current directory (/homes/yosefkl
) is /homes/yosefkl/yosefkl
. Try
realpath "$PWD"