Java Jive
2024-05-08 09:17:34 UTC
Consider a first code fragment for getting command-line parameters at
the start of a BATch file, everything works as it should:
:NextPar
IF %Debug% NEQ "" ECHO Parameter="%1"
IF /i "%1" EQU "/D" (
SET Debug="Y"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/N" (
SET Dummy="Y"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/S" (
SET ListSources="Y"
SHIFT
GOTO NextPar
)
IF %Debug% NEQ "" ECHO Debugging output ...
IF %Dummy% NEQ "" ECHO Dummy run, NOT actually making changes ...
IF %ListSources% NEQ "" ECHO Only listing sources ...
D:\Temp>fh /d /n /s
Parameter="/n"
Parameter="/s"
Parameter=""
Debugging output ...
Dummy run, NOT actually making changes ...
Only listing sources ...
Sources=<Correct hard coded CSV list of \\Server\Shares>
Known servers are:
<Correct list>
However, add in a section of code to add another possible command-line
parameter to replace the hard-coded list with a list of local drive
designations, and it fails unexpectedly:
IF /i "%1" EQU "/L" (
SHIFT
SET LocSources="%1"
IF %Debug% NEQ "" ECHO ">>>LocSources = '%LocSources%'<<<" & ECHO
">>>Parameter = '%1'<<<"
SHIFT
GOTO NextPar
)
10:15:10 D:\Temp>fh /d /n /s /l D:
Parameter="/n"
Parameter="/s"
Parameter="/l"
">>>LocSources = ''<<<"
">>>Parameter = '/l'<<<"
Parameter=""
Debugging output ...
Dummy run, NOT actually making changes ...
Only listing sources ...
Using only local sources '"/l"' ...
Known servers are:
"/l"
So the SET command fails to give LocSources any value, and the first
SHIFT in the new section is being completely ignored.
WTF?
the start of a BATch file, everything works as it should:
:NextPar
IF %Debug% NEQ "" ECHO Parameter="%1"
IF /i "%1" EQU "/D" (
SET Debug="Y"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/N" (
SET Dummy="Y"
SHIFT
GOTO NextPar
)
IF /i "%1" EQU "/S" (
SET ListSources="Y"
SHIFT
GOTO NextPar
)
IF %Debug% NEQ "" ECHO Debugging output ...
IF %Dummy% NEQ "" ECHO Dummy run, NOT actually making changes ...
IF %ListSources% NEQ "" ECHO Only listing sources ...
D:\Temp>fh /d /n /s
Parameter="/n"
Parameter="/s"
Parameter=""
Debugging output ...
Dummy run, NOT actually making changes ...
Only listing sources ...
Sources=<Correct hard coded CSV list of \\Server\Shares>
Known servers are:
<Correct list>
However, add in a section of code to add another possible command-line
parameter to replace the hard-coded list with a list of local drive
designations, and it fails unexpectedly:
IF /i "%1" EQU "/L" (
SHIFT
SET LocSources="%1"
IF %Debug% NEQ "" ECHO ">>>LocSources = '%LocSources%'<<<" & ECHO
">>>Parameter = '%1'<<<"
SHIFT
GOTO NextPar
)
10:15:10 D:\Temp>fh /d /n /s /l D:
Parameter="/n"
Parameter="/s"
Parameter="/l"
">>>LocSources = ''<<<"
">>>Parameter = '/l'<<<"
Parameter=""
Debugging output ...
Dummy run, NOT actually making changes ...
Only listing sources ...
Using only local sources '"/l"' ...
Known servers are:
"/l"
So the SET command fails to give LocSources any value, and the first
SHIFT in the new section is being completely ignored.
WTF?
--
Fake news kills!
I may be contacted via the contact address given on my website:
www.macfh.co.uk
Fake news kills!
I may be contacted via the contact address given on my website:
www.macfh.co.uk