Ich finde in awk keine Möglichkeit lokale Variablen, die nur in ihrer Funktion gültig sind, anzulegen. Im Moment behelfe ich mich damit die benötigten Variablen als Parameter im Funktionskopf mit anzugeben:
Gibt es auch eine richtege möglichkeit pattern anzulgegen ohne das es global wird?
Code:
##
# Resolves paths at the beginning of a location pattern as
# far as possible and prints the result. This feature makes it
# easier to work with symlinks.
#
# @param path The location pattern to resolve.
#
function resolvePath(path,
pattern) {
pattern = path;
# Select the resolvable part of the given path.
sub("[/]*[^/]*[?*].*$", "", path);
# Remember the part that cannot be resolved.
sub("^" path, "", pattern);
# If there is a resolveable part do so.
if (path) {
# If path exists, resolve and print it, else print the
# original string.
print("printf `[ -d " path " ] && (cd \"" path "\";pwd -P) || printf " path "`") | "sh";
close("sh");
}
# Append the unresolvable part.
printf("%s", pattern);
}

