Try $0 e.g.
echo "You are running $0"
Try $0 e.g.
echo "You are running $0"
Positional Peramaters is the concept your looking for.
There's built-in variables that represent the arguments passed to a script, $1 for the first thing passed, $2 for the second, etc. $# tells you how many.
There's a special Parameter, $0, which represents what your asking about -- the script itself. the zeroth argument.
To be pedantic, and completely thorough this is how man bash describes this parameter:
Special Parameters
"The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed."
0 Expands to the name of the shell or shell script. This is set
at shell initialization. If bash is invoked with a file of com‐
mands, $0 is set to the name of that file. If bash is started
with the -c option, then $0 is set to the first argument after
the string to be executed, if one is present. Otherwise, it is
set to the filename used to invoke bash, as given by argument
zero.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.