[Updated] usage of dirname to bash string manipulation