Search found 4 matches

by OJBakker
2023-Mar-15, 4:39 pm
Forum: Windows CMD Shell
Topic: Are there any scripts that DEPEND on NOT using Delayed Expansion?
Replies: 6
Views: 83

Re: Are there any scripts that DEPEND on NOT using Delayed Expansion?

Try this: @echo off setlocal disabledelayedexpansion echo disabled delayedexpansion set test=hello! set test set "test=hello!" set test endlocal setlocal enabledelayedexpansion echo enabled delayedexpansion set test=hello! set test set "test=hello!" set test set "test=hello^...
by OJBakker
2023-Mar-13, 12:07 pm
Forum: Windows CMD Shell
Topic: Use SED to extract part of a line?
Replies: 8
Views: 105

Re: Use SED to extract part of a line?

No need to use external tools. @echo off set "SegNr=" for /f tokens^=4^ delims^=^" %%A in ('more +34 text.txt') do if not defined SegNr set "SegNr=%%A" echo SegmentNumber=%SegNr% pause or @echo off (more +34 "text.txt")>"text_tmp.txt" set /p Line=<"t...
by OJBakker
2023-Mar-05, 3:02 pm
Forum: Windows CMD Shell
Topic: Is there any way to modify a variable twice in the same IF comparison?
Replies: 7
Views: 150

Re: Is there any way to modify a variable twice in the same IF comparison?

If you do not use delayed expansion and you are within a code block use ' call set ' to use the updated value of a variable changed within the code block. @echo off set x=2 set test=Hello if %x% equ 1 ( set test=Hi call set test=%%test%% There ) echo %test% set x=1 set test=Hello if %x% equ 1 ( set ...
by OJBakker
2022-Mar-23, 10:46 am
Forum: Windows CMD Shell
Topic: Command works if called in a subroutine, causes error in For loop?
Replies: 2
Views: 1417

Re: Command works if called in a subroutine, causes error in For loop?

The closing parenthesis ')' before '-azid( )' ends the for-parenthesized command block, then the next command becomes -azid and this is not a valid command. You need to escape the () inside the for command block to avoid this. Change '(' to '^(' and ')' to '^)' except for the parenthesis of the for-...