3

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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Alexander Mills
  • 9,330
  • 19
  • 95
  • 180
  • 1
    @jeffschaller has a good answer, but what is your actual goal, to learn the name of the shell? https://askubuntu.com/questions/590899/how-do-i-check-which-shell-i-am-using/1022440#1022440 – Evan Benn Aug 30 '19 at 01:44

1 Answers1

7

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.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250