bash and mksh cannot set a variable from a pipe

Solution Verified - Updated -


  • bash fails to set a variable when reading from a pipe:
    [user@localhost ~]$ echo foo | read bar
    [user@localhost ~]$ echo "bar=\"$bar\""
    [user@localhost ~]$
  • mksh also fails the same way


  • Red Hat Enterprise Linux, any version
  • bash, any version
  • mksh, any version

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content