For usage messages and such in my shell scripts I typically use prog=${0##*/} instead of prog=$(basename $0).
dirname can similarly be replace with ${var%/*}.
You noted the ''#' and '%' string operations, but I though you may want to call out the opportunity to avoid firing off a process.
Excellent work. I'm sharing with the folks on my team newer to shell, as it is chock full of examples I have learned and taught myself back in the day when I had to write resource efficient scripts than ran on a bunch of Unixes and POSIX(ish) shells.
For usage messages and such in my shell scripts I typically use
prog=${0##*/}
instead ofprog=$(basename $0)
.dirname
can similarly be replace with${var%/*}
.You noted the ''#' and '%' string operations, but I though you may want to call out the opportunity to avoid firing off a process.
Excellent work. I'm sharing with the folks on my team newer to shell, as it is chock full of examples I have learned and taught myself back in the day when I had to write resource efficient scripts than ran on a bunch of Unixes and POSIX(ish) shells.