Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing some sed (Unix Stream-Editor) commands from within windows batch-files, some sed pattern fail #2584

Open
bitsocket opened this issue Apr 30, 2024 · 2 comments

Comments

@bitsocket
Copy link

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

  1. run: sed -r 's/([Black "").*/[White "?"]/g' input.txt > output.txt from ConEmu directly
  2. run same command from a Windows batch-file (test.bat) - works also fine (see batch example above)
  3. 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

@bitsocket
Copy link
Author

test.bat.zip

@bitsocket
Copy link
Author

test.bat uploaded (unfortunately escape-characters from sed-commandlin example have apparenlty been removed during upload, but can be seen in the batch file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant