Executing some sed (Unix Stream-Editor) commands from within windows batch-files, some sed pattern fail
Opened this issue · 2 comments
Versions
ConEmu build: ConEmu version: 230724 stable (x64)
OS version: Windows 11 Pro (x64)
Used shell version: ConEmu (cmder) (Note: gitbash has same strange behaviour)
Problem description
Some sed commands do not work correctly when executed from Windows batch-file,
depending on replacement pattern, but all work fine when executed within the ConEmu (cmder) shell directly,
Windows batch-file example with unix sed examples
@echo off
echo --^> invoking sed for text-replaces in input-file ..
REM A) sed -r 's/([Black "").*/[White "?"]/g' input.txt > output.txt //--Works fine as expected!
REM B) sed -r 's/([Black ").*/[White "?"]/g' input.txt > output.txt //--does NOT work - pattern '[Black "'
REM is not replaced to '[Black "?"]', but instead is left as it is and redirect fails to output.txt (gets bypassed when executed via
REM windows batch-file), but both examples do work fine when DIRECTLY executed within ConEmu-shell (or git-bash).
echo ^* done.
GOTO FINISH
REM other script lines here
:USAGE
echo Usage
echo replace text with sed (stream-editor), line-by-line
echo Syntax: replace
:FINISH
echo.
echo ^* script is finished. ^*
echo.
goto :eof
Steps to reproduce
- run: sed -r 's/([Black "").*/[White "?"]/g' input.txt > output.txt from ConEmu directly
- run same command from a Windows batch-file (test.bat) - works also fine (see batch example above)
- now run: sed -r 's/([Black ").*/[White "?"]/g' input.txt > output.txt (from batch file) FAILS!
NOTE: Only difference in sed-command from step 3. is that search pattern has only one double-qoute: [Black " instead of two,
like in step 1. where search-pattern is: [Black "" !!
Actual results
sed command in Step 3. must work like example in Step 1. and replace pattern [Black " to [Black ""], when sed command
is executed from within a batch-file. But with sed command-line from step 3. redirect > to utput.txt suddenly fails !!
Expected results
Execution of command-line from Step 3. must behave the same as slightly different command-line from Step 1.,
when called from a batch file (see example above) in Windows. But instead, in Step 3. the redirect > to output.txt
all of a sudden fails / is ignored!
Additional files
Settings,
screenshots,
logs,
etc.
ConEmu.xml.zip
test.bat uploaded (unfortunately escape-characters from sed-commandlin example have apparenlty been removed during upload, but can be seen in the batch file.