calling batch file with semicolon in parameters from cygwin

Issue

I need to call a batch file from inside CYGWIN however one of it’s parameters is a path-like string containing semicolons. Normally in windows command line one could enclose that parameter in quotes (which would need to be trimmed later on). However this approach doesn’t wok in cygwin

Example batch (echoes first 3 parameters)

echo %1 
echo %2
echo %3

Windows cmd call

file.bat "a;b"  c 

Ouput

 "a;b"
 c
 empty

Cygwin call

 ./file.bat "a;b" c

Output

 a
 b
 c

Solution

Including space anywhere inside quotes will ensure that parameter with semicolon or comma is passed correctly. Although I have to admit that I do not understand this behavior whatsoever, it seems to be working flawlessly.

./file.bat "a;b " c

Output

"a;b"
c

As @jeb mentioned in his comment, enclosing quotes can be trimmed by accessing parameter variable like this

 %~1 

Answered By – pseudo

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published