Re: $0 variation questions



On 2011-01-30, Todd wrote:
On 01/30/2011 02:46 PM, Bit Twister wrote:
On Sun, 30 Jan 2011 14:25:11 -0800, Todd wrote:
Hi All,

In bash scripting is there a way to get

1) just the name of the script, no path,

_script_fn=$(basename $0)

Perfect. Thank you!


echo $_script_fn

no variables?

What do you mean by "no variables"?
In the script or the command line arguments $1, $2,...

if no variables in script, it would be

echo $(basename $0)

There's no need for an external command (see my previous post).

I mean the run line variables ($1 $2 etc.). And I was
mistaken. I thought $0 included then.

I still have to figure out how to get the
full path and name of the script.

You should have no need for that. If you do, you need to rethink
your script.

--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.



Relevant Pages

  • Re: [Full-disclosure] reduction of brute force login attempts via SSHthrough iptables --
    ... Anyhow its no problem at all to modify, so if you dont like it, just dont use it. ... on a lame script like this as long as it WORKS and is not insecure. ... echo "~ sorting out ip by ip" ... # echo "not enough failed logins, probably no attack from: ...
    (Full-Disclosure)
  • Ripping Tapes with Linux--How To
    ... the full script is located in the BASH ... My tape player is a portable style journalist's recorder from the ... The most irritating part of the recording process was setting the ... echo Starting de-noise procedure to file $TMP1 ...
    (comp.os.linux.misc)
  • Re: Linux Backup with Modification Date Filter?
    ... I wrote a bash script that acts as a wrapper to rsnapshot which first ... generates a modification-date filter, ...
    (comp.os.linux.misc)
  • Re: Command Script variable value lost during execution
    ... The value of RC_ver is numeric but ECHO would return it numeric or not... ... I checked ERRORLEVEL at the end of the script and it was 0 but again ... ECHO RoboCopy version xxx%RC_Ver%yyy ... CALL:GetRCVer RoboCopy.exe /Path ...
    (microsoft.public.windows.server.scripting)
  • Re: Bit Twister: Is this the dhclient-exit-hooks you were talking about?
    ... If you are running the dhclient then all you have to do is ... create the hooks script with YOUR CODE. ... DNS server with my wgets and then restart my firewall. ... You can put an echo statement on commands to show you what will happen ...
    (alt.os.linux)