Use the shell's suffix removal feature Use dirname. dirname can be used to strip the last component from a path: $ dirname -- "$str".
I wanted to be able to switch java versions by changing the $PATH value. So, in my bash shell, I can toggle simply by: $> jv6 java -version.
I need to extract file basename in bash running on Linux. How can I use bash to get basename of filename or directory name for given path?.