### Use the shell's suffix removal feature
str=/opt/oracle/app/oracle/product/12.1.0/bin/tnslsnr
path=${str%/*}
echo "$path"
In general, `${parameter%word}` removes `word` from the end of `parameter`. In our case, we want to remove the final slash and all characters which follow: `/*`.
The above produces:
/opt/oracle/app/oracle/product/12.1.0/bin
### Use dirname
dirname can be used to strip the last component from a path:
$ dirname -- "$str"
/opt/oracle/app/oracle/product/12.1.0/bin