Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

A somewhat humorous minor-request related to "Shift" command...

May
855
0
Two things:

Number one, for whatever reason, I tend to use the unadorned "Shift" command a lot. (Yes, there are several alternatives, but I tend to find the "Shift" command to be the simplest/easiest/most convenient.)

Number two, I have a batch file that "parses" the command name (%0) to eliminate the path to a file and the extension that I use as a standard technique in reporting errors, ala "@EchoErr "%@ExecStr[D:\DOS\BatchFileName %0]" ended due to error%@If[%ErrorCount != 1,(s)]".

The problem (which can be pretty much eliminated by a small amount of "pre-planning"), is this sequence reports that whatever parameter is the current 0th parameter after the "Shift" command(s) have been executed as the name of the batch file being executed.

The best "solution" at the present time is pretty simple: Save the value of the 0th argument into a variable at the top of the batch file. And there are (admittedly slight) problems with doing things this way: 1. I greatly dislike (a programming style that dates back more than 30 years) creating variables I really don't need (I have a prime programming goal that I try very hard to follow: The less the number of variables the better (unless not having a particular variable forces multiple recalculations/function calls for some reason)). 2: I am almost obsessive about not "polluting" the environment - I use "SetLocal" (with an "EndLocal [variable-names...]" to "export" the variables I want the "parent" environment to "know" about) whenever I am going to change to a (possibly) different disk drive and/or directory, create a variable that I'm not going to "export", create a function I don't want to "export", etc., etc., etc. And IMHO I don't understand why there is any reason that the "Shift" command should ever affect the command name variable (%0). It would be nice if this behavior was changed altogether (who could possibly be depending on this behavior) or a "/Switch" option of some kind be added to the "Shift" command to tell it to not include "%0" in its action(s). Just a minor complaint/suggestion...
 
Or you could just use the built-in %_BATCHNAME variable.

-Scott

mathewsdw <> wrote on 12/02/2011 04:41:40 PM:


>
> Two things:
>
> Number one, for whatever reason, I tend to use the unadorned
"Shift"command a

> lot. (Yes, there are several alternatives, but I tend to find the
> "Shift" command to be the simplest/easiest/most convenient.)
>
> Number two, I have a batch file that "parses" the command name (%0)
> to eliminate the path to a file and the extension that I use as a
> standard technique in reporting errors, ala "@EchoErr "%@ExecStr[D:
> \DOS\BatchFileName %0]" ended due to error%@If[%ErrorCount != 1,(s)]".
>
> The problem (which can be pretty much eliminated by a small amount
> of "pre-planning"), is this sequence reports that whatever parameter
> is the current 0th parameter after the "Shift" command(s) have been
> executed as the name of the batch file being executed.
>
> The best "solution" at the present time is pretty simple: Save the
> value of the 0th argument into a variable at the top of the batch
> file. And there are (admittedly slight) problems with doing things
> this way: 1. I greatly dislike (a programming style that dates back
> more than 30 years) creating variables I really don't need (I have a
> prime programming goal that I try very hard to follow: The less the
> number of variables the better (unless not having a particular
> variable forces multiple recalculations/function calls for some
> reason)). 2: I am almost obsessive about not "polluting" the
> environment - I use "SetLocal" (with an "EndLocal [variable-
> names...]" to "export" the variables I want the "parent" environment
> to "know" about) whenever I am going to change to a (possibly)
> different disk drive and/or directory, create a variable that I'm
> not going to "export", create a function I don't want to "export",
> etc., etc., etc. And IMHO I don't understand why there is any reason
> that the "Shift" command should ever affect the command name
> variable (%0). It would be nice if this behavior was changed
> altogether (who could possibly be depending on this behavior) or a
> "/Switch" option of some kind be added to the "Shift" command to
> tell it to not include "%0" in its action(s). Just a minor
> complaint/suggestion...
>
>
 
How about using %_batchname instead?
Thank you David, as is fairly typical, I don't know about the things I don't know about. (I've been using this product since about Windows 3.1, and I haven't "perused" the documentation in a detailed way (I just take a look at "What's New") in quite a long time (and given my often-mentioned very bad memory, there is some doubt whether that would even be worthwhile)).
 

Similar threads

Back
Top