This behaviour is easy to observe with the following command line:

$ rm -f daao.*; strace -ff -o daao dash -c 'set -x; z=`echo | cut -f1 | sort`'

and then

$ grep write daao.*
daao.6716:write(2, "+ ", 2)                       = 2
daao.6716:write(2, "z=", 2)                       = 2
daao.6716:write(2, "\n", 1)                       = 1
daao.6718:write(2, "+ ", 2)                       = 2
daao.6718:write(2, "echo", 4)                     = 4
daao.6718:write(2, "\n", 1)                       = 1
daao.6718:write(1, "\n", 1)                       = 1
daao.6719:write(2, "+ ", 2)                       = 2
daao.6719:write(2, "cut", 3)                      = 3
daao.6719:write(2, " -f1", 4)                     = 4
daao.6719:write(2, "\n", 1)                       = 1
daao.6719:write(1, "\n", 1)                       = 1
daao.6720:write(2, "+ ", 2)                       = 2
daao.6720:write(2, "sort", 4)                     = 4
daao.6720:write(2, "\n", 1)                       = 1
daao.6720:write(1, "\n", 1)                       = 1

The subshells in pipeline prints their own commands before executing
it, using multiple syscalls giving possibility of intermixed output
when context switches happen in between...

For comparison this is what bash gives:

zao.6858:write(2, "+ z=\n", 5)                   = 5
zao.6860:write(2, "++ echo\n", 8)                = 8
zao.6860:write(1, "\n", 1)                       = 1
zao.6861:write(2, "++ cut -f1\n", 11)            = 11
zao.6861:write(1, "\n", 1)                       = 1
zao.6862:write(2, "++ sort\n", 8)                = 8
zao.6862:write(1, "\n", 1)                       = 1


An alternative to concatenate strings to a buffer before writing
one could try using gather write with writev() (I don't know the
SMOP factor there as I did not peek the dash source code :)

Tomi


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to