![]() ![]() It strips from the left of ls's output as little as it must to fully contain the link's name and the string ->. The current directory must be changed to its initial value first in order to reliably handle any referent paths and so, in the command substitution subshell the function does: cd -.ls.echo / In that case it calls while loop in a subshell. In this way it handles any file type argument which the shell has permissions to address unless $1 is a symbolic link that does not point to a directory. If it cannot it checks that $1 exists and is not a soft link. If it can it prints the argument's canonical path to stdout. It tries to quit each of its arguments as soon as it might. It does a lot of directory changing, but, other than setting it to its canonical value, it does not affect $PWD, though $OLDPWD cannot by any means be counted upon when it is through. It also looks for the $_zdlm variable (which it also unsets when it is through) and prints its C-escaped value immediately to the right of each of its arguments, each of which is always followed also by a single \newline character. Called without arguments and that's about it but called with them and it will resolve and canonicalize the path for each or else print a message to stderr why not.īecause it mostly operates in the current shell it should be able to handle an argument list of any length. In general all of these dependencies should be pretty reliably available on a Unix machine.Ĭalled with or without arguments the first thing it does is reset $PWD to its canonical value - it resolves any links therein to their targets as necessary. It will still function just fine without the latter, though it may overwrite then unset some current shell functions in that case. It depends on a POSIX-compatible shell and a POSIX-compatible ls as well as a clean _function() namespace. It strives to do as much as it might in the current shell - without invoking a subshell - though there are subshells invoked for errors and soft links which do not point to directories. ) else ( PS4=ERR:\ NO_SUCH_PATH set -x : "$1" ) If you have readlink, you can call it in a loop: realpath () " ]ĭo set " $1" "$(_cd - ls -nd - "$1" echo /)" ![]() readlink -f works on Linux (excluding some stripped-down BusyBox systems), FreeBSD, NetBSD, OpenBSD and Cygwin, but not on OS/X, AIX, HP/UX or Solaris. If you meant a path with all symbolic links resolved, that's a different matter. This works in any Bourne-style shell, by the way. a path from the root directory: case $0 in Assuming you really meant the absolute path, i.e. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |