Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Say I run the following on /some/path:

for x in foo/*; do
print $x
done

Are there any parameters I can use to tell Zsh to print, not just the filename, but the full absolute path to $x? (without explicitly hard-coding /some/path in the print statement.

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted
for x (foo/*(:A)) print -r $x

Or:

for x (foo/*) print -r $x:A

Though in this case:

print -rl foo/*(:A)

is enough.

:A expands symbolic links. You can also use :a which doesn't.

share|improve this answer
add comment

You can use the a history expansion modifier in a glob qualifier.

for x in foo/*; do
    print -r $x(:a)
done

With :A instead of :a, symbolic links are expanded.

share|improve this answer
add comment

If you prepend the path to the pattern, $x will expand to the full path:

for x in /some/path/foo/*; do
  print $x
done

But I'm not sure if this is exactly what you're looking for?

If you don't want to hardcode /some/path and you want the code always to look in the current directory, use $PWD:

for x in $PWD/foo/*; do
  print $x
done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.