Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`docker run` output to bash variable - strange behaviour

I'm seeing some strange behaviour getting the output from docker run into a bash variable.

Simple example:

#!/bin/bash

PWD=$(docker run --rm -ti ubuntu pwd 2>&1)
# also tried with PWD=`docker run ...` with same behaviour
echo $PWD
echo abc $PWD
echo abc $PWD xyz

output

/
abc /
 xyz/

The problem is on the last echo...

like image 304
gingerlime Avatar asked Feb 10 '26 00:02

gingerlime


1 Answers

you need to modify the docker run --rm -ti ubuntu pwd 2>&1 with docker run --rm ubuntu pwd 2>&1 probabilly the interactive and tty mode doesn't work fine in a shell variables

like image 93
Gianmarco Carrieri Avatar answered Feb 12 '26 16:02

Gianmarco Carrieri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!