Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate env variable value with string in command line

This is Windows 7 command prompt question.

Suppose I have environment variable which were set in a next way:

set FILE_SRC="D:\Users\me\Documents and Settings"

I would like to call form command line utility which will get one of directory files as argument:

fooUtil.exe %FILE_SRC%\fileName.txt

In this case shell fails to construct correct path string. Instead of it utility get next argument:

"D:\Users\me\Documents and Settings"\fileName.txt

What is a correct way? Again, I talk about prompt command line and not a batch file.

like image 826
BaruchLi Avatar asked Oct 15 '25 15:10

BaruchLi


2 Answers

I make it so ...

set "FILE_SRC=D:\Users\me\Documents and Settings" fooUtil.exe "%FILE_SRC%\fileName.txt"

This works also with special characters.

set "line=lines & edges = figures" @echo "%line%"

like image 111
nanogrid Avatar answered Oct 18 '25 08:10

nanogrid


Just skip the quote marks when setting the variable. The variable will be set to the value terminated by a newline, not space.

like image 44
Peter Avatar answered Oct 18 '25 08:10

Peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!