After updating sed
to 4.4
version, sed
doesn't replace spaces with commas in the output of find
command given to it as here-string
:
sed --version
sed (GNU sed) 4.4
ls -l /tmp/test/
total 0
-rw-r--r-- 1 root root 0 Jan 9 17:25 a
-rw-r--r-- 1 root root 0 Jan 9 17:25 b
NOT EXPECTED
sed "s: :,:g" <<< $(find /tmp/test/ -type f)
/tmp/test/b
/tmp/test/a
There are no issue in sed
4.2
sed --version
sed (GNU sed) 4.2.2
ls -l /tmp/test/
total 0
-rw-r--r-- 1 root root 0 Jan 9 17:25 a
-rw-r--r-- 1 root root 0 Jan 9 17:25 b
as expected
sed "s: :,:g" <<< $(find /tmp/test/ -type f)
/tmp/test/a,/tmp/test/b
As a workaround, storing the result in variable and using echo
helps:
a=$(find /tmp/test/ -type f)
echo $a | sed "s: :,:g"
/tmp/test/b,/tmp/test/a
How to achieve the same output in sed
4.4 using here-string
?
Update
version of bash changed as well between the two systems:
bash --version
GNU bash, version 4.4.20
old version
bash --version
GNU bash, version 4.3.48
echo $a
toecho "$a"
. Any difference? – Chris Davies Jan 09 '22 at 17:39find ... | sed ...
– Chris Davies Jan 09 '22 at 17:44echo "$a" | sed "s: :,:g"
behaves likesed
– rokpoto.com Jan 09 '22 at 17:45