dos - Passing exclamation marks as parameters in batch subroutine call -
thanks community have learned how escape exlamation marks immediate use in batch delayedexpansion block. (use 2 escape carets not one, awesome)
but can't seem find or figure out how pass contents of variable containing exclamation mark parameter batch subroutine.
example:
@echo off setlocal enabledelayedexpansion set variable=hello^^! echo "!variable!" call :subroutine "!variable:^^!=^^!!" pause exit :subroutine echo "%~1" exit/b
output:
"hello!" "hello" press key continue . . .
i want second "hello" include exclamation mark. have tried various permutations of substring replacement on line 5 no avail.
help
you need different way variable replacing, , more carets.
@echo off setlocal enabledelayedexpansion set variable=hello^^! echo "!variable!" call :subroutine %variable:!=^^^^^^^^^^!% exit /b :subroutine echo %~1 exit /b
or quotes: call :subroutine "%variable:!=^^^!%"
in function need expand %1
without quotes, number of carets odd in call
parameter.
but @ it's bad idea try such things.
agree aacini, should use pass reference instead.
way handle any possible content.
@echo off setlocal enabledelayedexpansion set variable=hello^^! echo "!variable!" call :subroutine variable exit /b :subroutine echo !%1! exit /b
Comments
Post a Comment