Say I have ~/scripts
in my $PATH
and I have script.sh
inside that path.
I can execute that script by typing script.sh
directly in the terminal, but what if I want to print out the full path of that script without knowing the base path of the script (or added any function inside the script to print out its own path)? Are there any good ways to do this?
which script.sh
should do itwhich
, there are builtins that are well suited for that, liketype
,hash
andcommand
, unlesswhich
is a builtin also from the shell you're using then sure use it.man hash
to see the corresponding help page.bash -c 'help hash'