2

I have a Docker container myContainer and two simple batch scripts:

  • generateShell.bat
@echo off 
echo #!/bin/bash > helloworld.sh
echo ...>> helloworld.sh
  • runShell.bat
@echo off 
call generateShell.bat
docker exec -i myContainer bash < helloworld.sh

When I run runShell.bat, helloworld.sh runs in Docker container. I want to generate something in helloworld.sh so that writes output to .txt file in container. I tried

echo echo Hello World > output.txt>> helloworld.sh

but in that case I get only

Hello World

in Windows command prompt and no generated .txt files neither in container nor on host.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
sovesti
  • 35
  • 4
  • 1
    You might be better off writing the script directly (instead of using a shell script to write it), `COPY`ing it into an image (instead of passing it on stdin), and making it a container's `CMD` (instead of using `docker exec`). You can use command-line arguments or environment variables to customize the script's behavior at runtime. Does that approach simplify this setup at all? – David Maze Jun 17 '20 at 12:25
  • My original problem compels me to generate shell script with parameters. Customizing script's behavior with arguments called several other bugs related to some Shell peculiarities, so it's not my path at all. – sovesti Jun 17 '20 at 12:33
  • 2
    Do you mean like this, `echo echo Hello World ^> output.txt >> helloworld.sh`? – Compo Jun 17 '20 at 17:14
  • @Compo, wow, it worked, thank you so much! If you know, why it did, can you write it like an answer? – sovesti Jun 17 '20 at 18:41

0 Answers0