Wednesday, October 17, 2012

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.

No comments: