OSX basename Command – Troubleshooting Issues

basenameosx

I have this command:

 base_name="$(basename "$0")";

and I am getting this error:

basename: illegal option — b

usage: basename string [suffix]
basename [-a] [-s suffix] string […]

anyone know what's going on with that?

Best Answer

My lucky guess would be that $0 contains the string -bash and so your command becomes:

basename -bash

which basename interprets as a single-character option "b". Change that to:

base_name="$(basename -- "$0")";

... so that basename is told to stop looking for options.

Related Question