Bash string variable manipulation

In a bash script I've set a variable that is the directory name of where an executable lives.

the_dir=`dirname $which myscript`

which equates to something like "/path/to/dir/bin"

I need to cut that down to remove the "bin" so I now have "/path/to/dir/".

This sounds easy but as a complete novice I'm getting lost.
How do I do it and more importantly what is the best tool for this job so I can do a lot of reading?

Thanks.

a=/path/to/dir/bin
echo ${a%/*}

---------- Post updated at 09:22 AM ---------- Previous update was at 09:21 AM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Hi,

Indeed it is easy (after spending hours and hours and hours ...)
You can use string manipulation to achieve your objective via:

new_dir=${the_dir%/bin*}

Essentially, it matches /bin and anything after that hence the * and returns the left of the string that was not matched.

A.