Re: $0 variation questions



On Sun, 30 Jan 2011 15:00:13 -0800, Todd wrote:

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

When in doubt, use echo $some_var_here or better yet

echo " >$some_var_here<" to detect any leading/trailing white space.

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

You already know how to get name of script.

As you have seen, ./script_fn, bit you, and if you look at $PATH the
script could be in one or more places.

You can test first character for . and if so use $PWD.
Then run result through type. Here is a quick untested kludge

_exe=$0
_char1=${$_exe:0:1}

if [ "$_char1" = "." ] ; then
_exe=$PWD/${$_exe:2}
fi

set -- $(type $0)
_fn=$1
_dir=${3%$_fn}

echo $_fn $_dir
.



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: C shell - cd
    ... > echo `pwd` ... > The echo statement does display the newdir path but it doesn't actually ... Your script executes in a separate process; ...
    (comp.unix.shell)