Need your help. The question is:
1) We have directory '/SomeDirectory/SubDirectory'
2) And have symlink pointing to it like '/AnotherOneDirectory/symlink'
'/AnotherOneDirectory/symlink' -> '/SomeDirectory/SubDirectory'
3) Need to get real path without symlinks knowing only '/AnotherOneDirectory/symlink'
4) P.S. Using shell commands only. Something like realpath() call for C.
What are you talking about? It isn't homework!!!
It is issue I found during my work with shell. If you have no idea how to resolve it I understand you, this is not trivial task, as it can appear at the first look.
We can use find, pwd and other tools, but they don't provide us with real path. Unfortunately
Your question made be think about the real reason... Hm...
I found that I don't know how to retrieve full real path in shell and it confused me. Of course, I can write something like
in C++ program and use it. But it is not a solution for each system, where our additional binary is missed. Say at my friend home
---------- Post updated at 09:36 PM ---------- Previous update was at 09:29 PM ----------
So the 1st way I can see is to use something like
ls -l "directoryname" | cut -f2 -d '>' | sed 's/^ //'
It isn't graceful way, don't you think so? As for me: it is usable but depends on ls standard, and possible differences between UNIX systems. Doesn't it?