I have a batch file in with the following parameter hard coded
SET upgrade=false
I want to give user an option to explicitly define the upload parameter. By default it should be false and if user explicitly define upgrade=true
I should treat it as true.
I also wants to check the validation for boolean value in upload parameter.
I am new to batch file processing. I have tried with the default value processing.
if "%2"=="" goto false
:false
SET upgrade=false
In the batch script, you can get the value of any argument using a % followed by its numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on. If you require all arguments, then you can simply use %* in a batch script.
For example, entering C:\abc.exe /W /F on a command line would run a program called abc.exe and pass two command line arguments to it: /W and /F.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
%0 is the name of the batch file. %~n0 Expands %0 to a file Name without file extension.
Easy, try this. To set upgrade to true
use /U
as a parameter:
@echo off
set upgrade=FALSE
:parse
if /i "%1" EQU "/u" set upgrade=TRUE
if /i "%1" EQU "/?" Echo HELP MSG & goto :eof
if "%1" NEQ "" (shift /1 & goto :parse)
And then you can add on the rest of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With