All of lore.kernel.org
 help / color / mirror / Atom feed
* Dash only reads the first character from pipe (bash reads whole line)
@ 2015-11-13 23:24 Gioele Barabucci
  2015-11-14 10:51 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Gioele Barabucci @ 2015-11-13 23:24 UTC (permalink / raw)
  To: dash

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

 > 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
 >
 > # /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 <gioele@svario.it>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Dash only reads the first character from pipe (bash reads whole line)
  2015-11-13 23:24 Dash only reads the first character from pipe (bash reads whole line) Gioele Barabucci
@ 2015-11-14 10:51 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2015-11-14 10:51 UTC (permalink / raw)
  To: Gioele Barabucci; +Cc: dash

Gioele Barabucci <gioele@svario.it> wrote:
> 
> > 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
> >
> > # /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,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-14 10:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-13 23:24 Dash only reads the first character from pipe (bash reads whole line) Gioele Barabucci
2015-11-14 10:51 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.