0

I asked a question yesterday about how to manage to get %% around a variable without getting the evaluation. Well, the thing is, it does not work that way in my case...

I have a .bat file which gets an input parameter. Later on I want to use the value of this input parameter and put %...% around, like:

call script.bat testValue

script.bat:

 set inputPar=%1
 set newValue=%%inputPar%%

Now I get:

 echo %inputPar%
testValue
 echo %newValue%
%inputPar%

But I would like to get:

echo %newValue%
 %testValue%

Is that somehow possible?

2 Answers 2

2

The reason you're getting those results is because %%inputPar%% is being treated as %%inputPar%% and %% becomes a literal %.

You need:

first.cmd:
    @echo off
    call script.cmd testValue
script.cmd:
    @echo off
    set inputPar=%1
    set newValue=%%%inputPar%%%
    echo %inputPar% should be testValue
    echo %newValue% should be %%testValue%%

This gives you %%%inputPar%%% and, again, %% becomes a literal % with %inputPar% becoming testValue.

Sign up to request clarification or add additional context in comments.

Comments

0

I found the solution:

set inputPar=%1

set inputParDollar=%%%inputPar%%%

:: installDir is an already set environment variable

set installDirDollar=%%%installDir%%%

echo inputPar: %inputPar%

echo inputParDollar: %inputParDollar%

echo installDirDollar: %installDirDollar%


call script.bat testValue

inputPar: testValue

inputParDollar: %testValue%

installDirDollar: %D:\testenv%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.