Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:00:28+00:00 2026-06-02T01:00:28+00:00

In bash you can do: echo test >&1 (redirect to stdout, although it’s already

  • 0

In bash you can do:

  • echo test >&1 (redirect to stdout, although it’s already going there)
  • echo test >&2 (redirect to stderr)
  • echo test >&0 (redirect to stdin)

When I do the last one my terminal still prints test as it would with the other two, but it’s hard to know why. So first off, why does this work at all? Secondly, are there any good uses for redirecting to stdin?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:00:30+00:00Added an answer on June 2, 2026 at 1:00 am

    To be more precise, what >&0 does is duplicate file descriptor 0 as file descriptor 1. If the program’s stdin is only open for reading, then when your program tries to write to stdout (file descriptor 1), it will get an error because file descriptor 1 is also only open for reading.

    You can demonstrate this by writing a small shell script that inspects its own file descriptors:

    10156115.sh:

    #!/bin/bash
    bash -c 'ls -l /proc/$$/fd' >&0
    

    And then invoke it with identifiable stdin, stdout and stderr:

    $ touch stdin
    $ ./10156115.sh < stdin > stdout 2> stderr
    

    The result is that you get the following in stderr:

    ls: write error: Bad file descriptor
    

    However, by default, all three are a terminal: (output simplified)

    $ ls -l /proc/$$/fd
    lrwx------ 0 -> /dev/pts/14
    lrwx------ 1 -> /dev/pts/14
    lrwx------ 2 -> /dev/pts/14
    lrwx------ 255 -> /dev/pts/14
    

    Typically, all three are actually open read+write, so the >&0 redirect has no effect at all if used alone from a normal shell.


    Are there any uses for this?

    There aren’t any common uses of this, but you might use it as a dirty hack to get a way to print to the terminal if whomever calls your script redirects stdout and stderr, and for whatever reason you’re not able to change that:

    if [ ! -t /dev/fd/1 -a ! -t /dev/fd/2 -a -t /dev/fd/0 ]; then
        echo "My message that I really, really want to go to a terminal" >&0
    fi
    

    But I wouldn’t recommend actually doing this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Bash I can easily do something like command1 && command2 || command3 which
Is there a Linux utility or a Bash command I can use to sort
Suppose I have variable x in bash. How can I test if it's some
Why can't the folder be found? I double checked that it exists. #!/bin/bash echo
Is there a way to programmatically test whether ssh can authenticate using a public
I have a string in Bash: string="My string" How can I test if it
In bash how can I make a construction like this to work: if (cp
In Bash I can create a map (hashtable) with this common construction hput() {
I have terminal.app set to accept utf-8 and in bash I can type unicode
How can I make symfony completion in bash? Have ubuntu 9.10. It's hard to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.