shell: basename and dirname through Parameter Expansion

If you want to have basename and dirname a little faster through shell builtins, you may want to try these in bash or Korn Shell:
  • basename: ${file##*/}
  • dirname: ${file%/*}
I don’t really recommend to use these substitutes, I still find basename and dirname quite readable and I am not using them in a loop anyway.

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.