Skip to main content
... as to not let filename globbing take effect (there's still the issue with files named "-n" etc.)
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Use basename to strip the leading path off of the files:

for file in sample/*; do
    echo $"$(basename "$file")"
done

Though why not:

( cd sample; ls )

Use basename to strip the leading path off of the files:

for file in sample/*; do
    echo $(basename "$file")
done

Though why not:

( cd sample; ls )

Use basename to strip the leading path off of the files:

for file in sample/*; do
    echo "$(basename "$file")"
done

Though why not:

( cd sample; ls )
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

Use basename to strip the leading path off of the files:

for file in sample/*; do
    echo $(basename "$file")
done

Though why not:

( cd sample; ls )