On Thursday 30 May 2019 12:07:13 pm Nathan Stratton Treadway wrote: > 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 > Sounds interesting Nathan. If I have to work on it again. I'll try to keep that in mind. "basename $0" I assume sets $basename by stripping off the leading path includeing the ./ ? That would rather simplify that bit of logic.
Thanks Nathan. Copyright 2019 by Maurice E. Heskett Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page <http://geneslinuxbox.net:6309/gene>