bluemunch bluemunch - 5 months ago 17
Bash Question

How can I use inline variables in a .bat file?

I need to convert the following to be compatible with a batch script.

cmd.exe cd " + homepath + "\\" + a
mvn archetype:generate -DarchetypeCatalog=file://"+ homepath + "/.m2/repository
1
c
b
c
uuid.toString()
Y
cd " + homepath +"\\"+ a +"\\" + b
vn clean install
"cd " + homepath +"\\" + a
a
cd " + homepath +"\\" + a +"\\" + b + "\\" + b + "-plugin" + "\\target
jar -xvf " + zipDirectory
cmd cd " + homepath +"\\" + a +"\\" + b + "\\" + b + "-plugin" + "\\target\\" + "\\META-INF\\maven\\" + c + "\\" + b + "-plugin
copy pom.xml " + pluginDirectory
cd " + pluginDirectory
rename pom.xml " + b + "-plugin-1.0.0.pom
color 0a


For a line like the first one:

cmd.exe cd " + homepath + "\\" + a


Would the line look like this?

SET homepath = C:\Users\Joe\
SET a = plugins
cmd.exe cd echo %homepath% echo %a%

Answer

in batch, there is no string concatenation symbol like on (other) programming languages. You just use the variable instead of the string:

set homepath=%userprofile%
set a=plugins
echo homepath is %homepath% and a is %a%.
cd %homepath%\%a%

(Note: do not use spaces around = with the set command - they would be part of the variable name respectively the value)

Comments