I am trying to truncate a string in bash, specifically to get into the directory of an executable linked by a symlink. For example:
[alva@brnzn ~ $] ls -algh $(which python3.4)
lrwxr-xr-x 1 admin 73B 26 May 02:49 /opt/local/bin/python3.4 -> /opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4
So i cut out the fields I don't need:
[alva@brnzn ~ $] ls -algh $(which python3.4) | cut -d" " -f 14
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4
I need help to cut out everything after the last /
. I am interested in a solution were I can save the previous string in a var and using variable expansion to cut out the part of the string I dont need. e.g. printf '%s\n' "${path_str#*/}"
(this is just an example).
Thank you!