bash and mksh cannot set a variable from a pipe

Solution Verified - Updated -

Issue

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

Environment

  • 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 of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.