[NTLUG:Discuss] BASH - Get name of my script that is executing

Darin W. Smith darin_ext at darinsmith.net
Thu May 15 16:12:06 CDT 2003


On Thu, 15 May 2003 20:46:30 +0000, jay linux <jaylinux at hotmail.com> wrote:

> I would have sworn I had written a BASH script that got and printed it's 
> own name using a built in variable or something. But I can't find it?
>
> Does anyone remember anything like that?
>
> Thanks, Jay
>

Yes.  $0 is what you want.

So, if you have myscript.sh:
#!/bin/sh
echo $0

and you run ./myscript.sh

your output should be:
./myscript.sh

-- 
D!
Darin W. Smith
AIM: JediGrover



More information about the Discuss mailing list