Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass blank to batch file as parameter

Tags:

batch-file

I need to pass blank("" or " ") to a batch file as parameter.

I have to pass the runtime values to a url. My url is:

start iexplore http://example.com?emailAddress=%1&name=%2&phone=%3&dateofbirth=%4&hobby=%5&address=%6

Everything works fine if all parameters have some value, but if the value of any of the parameters is "" or " ", i.e., blank, the next non-blank value is assignment and the sequence is disordered.

Please help !

like image 710
iAmLearning Avatar asked Feb 11 '14 14:02

iAmLearning


People also ask

How do you echo a blank line in a batch file?

To create a blank line in a batch file, add an open bracket or period immediately after the echo command with no space, as shown below. Adding @echo off at the beginning of the batch file turns off the echo and does not show each of the commands. @echo off echo There will be a blank line below. echo.

How do I parameterize a batch file?

Batch parameters (Command line parameters): 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.

What does %% do in batch?

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. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What is %~ n0 in batch file?

Note: %0 is the name of the batch file. %~n0 Expands %0 to a file Name without file extension.


1 Answers

Use %~x instead of %x (where x is your parameter number)

This removes any enclosing quotes from the paramater, hence

echo parameter3=%~3

would show parameter3=

if you called this with yourbatch one two "" four

If you pass "space" as a parameter then this will show a space as %~3 (which is a bit hard to see - try appending an obvious string)

In either case, if you use %x then you'd show enclosing quotes - either "" or " " depending on which you passed in that position. You probably don't want quotes just there...

like image 122
Magoo Avatar answered Sep 28 '22 21:09

Magoo