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

May 24, 2010
855
0
Northlake, Il
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...
 

samintz

Scott Mintz
May 20, 2008
1,514
18
Solon, OH, USA
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...
>
>
 
May 24, 2010
855
0
Northlake, Il
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
Thread starter Title Forum Replies Date
M How to? An admittedly somewhat silly question regarding elevation... Support 2
M Somewhat inconsistent limitations… Support 4
M (Somewhat unbelievable) Do While Behavior/Question Support 1
Peter Murschall Some minor flaws Support 15
Alpengreis Documentation Minor issue in help file for view /E Support 1
D WAD Minor Post Installation Bug in V18 Support 1
dcantor Help file minor error Support 0
R Minor Cosmetic Issue in Take Command Window Support 2
D Minor problem. Incorrect value internal var _dir_files Support 7
jbanaszczyk help files: minor inconsistency Support 2
D Fixed Minor problem: output not alligned in the tree command Support 1
S Suggested minor improvements for www.jpsoft.com Support 5
M Just a minor annoyance re one particular plugin... Support 25
M Just a minor oddity... Support 9
Dan Glynhampton Documentation v15 help: Minor niggles Support 0
Dan Glynhampton Documentation Minor issues with HELP Support 0
M A minor complaint... Support 9
M A (minor) limitation of @FileSize... Support 6
Charles Dye Minor nit: DIR /F, IFTP, colorization Support 4
vefatica Install two minor versions Support 4
A minor documentation fix - command line editing Support 0
A del /w [minor documentation fix] Support 0
A Minor documentation fix ["-" on command line] Support 3
Roedy WAD Minor long-standing install problems Support 6
M A minor but annoying issue with the "MD" command... Support 20
R A couple of minor issues with new forum. Support 4
gschizas (minor) Help topic "Colors, Color Names and Codes" is wrong Support 0
M Minor "For" issue... Support 1
M A question about new behavior that’s a minor irritation… Support 16
M An undocumented limitation and an associated minor bug... Support 1
S SETARRAY - minor issue Support 0
H Minor bug in v12 SENDMAIL Support 0
J ZIP Help - minor quibble Support 0
S BDEBUGGER - minor issue Support 2
gschizas Minor (really minor) registration issue Support 0
S Virtual disk detection, minor enhancement requests Support 0
S Minor HELP issues Support 1
Charles Dye Minor installer quirk Support 1

Similar threads