On Thu, May 30, 2019 at 09:12:53 -0400, Gene Heskett wrote:
> I found it, I think. In an effort to make my script immune to the
> instant pwd of the launching shell, I had written an if statement:
>
> if [ $0 == "./backup.sh" ] || [ $0 == "${MYDIR}/backup.sh" ] || [ $0
> == "backup.sh" ] ; then
(If your goal is to let the script figure out it was invoked using the
name "backup.sh", you might want to use the "basename" command instead.
You can see an example in the script pointed to by both /bin/lesspipe
/and bin/lessfile [under Debian], which contains:
BASENAME=`basename $0`
near the top and then checks if that equals "lessfile" at various points
through the script, with the net effect that it behaves in "file" mode
as long as the final component of the path used to invoke the script is
"lessfile".
In your case, probably you can just replace your if statement with
if [ `basename $0` == "backup.sh" ]; then
...only be sure to test carefully afterwards to make sure it really does
what you are actually intending....)
> Now, is that 3rd "or" anything but trash code? I think it could probably
> could be removed as I can't think of a launch condition that would make
> it true.
(It would trigger if backup.sh were found in your path and you just used
the unprefixed name to run the script. But if you switch to the
basename approach, the prefix part of your invocation won't matter.)
Nathan
----------------------------------------------------------------------------
Nathan Stratton Treadway - [email protected] - Mid-Atlantic region
Ray Ontko & Co. - Software consulting services - http://www.ontko.com/
GPG Key: http://www.ontko.com/~nathanst/gpg_key.txt ID: 1023D/ECFB6239
Key fingerprint = 6AD8 485E 20B9 5C71 231C 0C32 15F3 ADCD ECFB 6239