You are not logged in.
I have a function in a batch file like so
@echo off
setlocal EnableDelayedExpansion
call :myFunc input1
:myFunc
set input=!%~1:str1=str2!
echo !input!
At the line
set input=!%~1:str1=str2!
I want to substitute str1 in input1 with str2. But I am not able to get the syntax right to use %~1 here.
If I use another temporary variable it works, but I do not want to resort to using an extra variable.
Working code
@echo off
setlocal EnableDelayedExpansion
call :myFunc input1
:myFunc
set temp=%~1
set input=!temp:str1=str2!
echo !input!
Offline
You can't perform substitutions in %1 (etc); the only solution is to assign a variable as you have done in your working example.
Last edited by bluesxman (22 Nov 2019 13:47)
cmd | *sh | Ruby | Chef
Offline