5

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.

Josh
  • 1,694
  • 3
  • 16
  • 32

3 Answers3

8
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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
3

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
D_Bye
  • 13,797
  • 3
  • 42
  • 31
1

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
Martin von Wittich
  • 13,857
  • 6
  • 51
  • 74