Skip to contentSkip to conversation

Dash only reads the first character from pipe (bash reads whole line)

DISCUSSION Gioele Barabucci 2 participants 2 messages Nov 13, 2015 – Nov 14, 2015

lore
Share & tools
lore
#0 lore raw

Hello,

a 6 year old Debian bug [1] describes a problem with reading from pipes that is still present in the current dash version (I tested up to git commit 7062c78).

The following test, by the original reporter, shows the problem

Quoted 10 lines

The 'read' command seems to only read the first character and not the > whole line.

Example / comparison with bash:

# /bin/dash
# sudo modprobe nf_conntrack
# read MAX </proc/sys/net/netfilter/nf_conntrack_max
# echo $MAX
2
Quoted 4 lines
# /bin/bash
# read MAX </proc/sys/net/netfilter/nf_conntrack_max
# echo $MAX
262144

It this a known problem? Are there workarounds?

Regards,

[1] https://bugs.debian.org/547902

--
Gioele Barabucci <[email protected]>

#1 lore raw
Quoted 12 lines · Gioele Barabucci
Quoted 12 lines

The 'read' command seems to only read the first character and not the whole line.

Example / comparison with bash:

# /bin/dash
# sudo modprobe nf_conntrack
# read MAX </proc/sys/net/netfilter/nf_conntrack_max
# echo $MAX
2
Quoted 6 lines
Quoted 4 lines
# /bin/bash
# read MAX </proc/sys/net/netfilter/nf_conntrack_max
# echo $MAX
262144

It this a known problem? Are there workarounds?

Yes it's a known problem, but arguably it's more of a kernel bug than a dash bug (proc files cannot be read byte-by-byte). You can work around it using cat

MAX=$(cat /proc/.../file)

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt