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 7510413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:13:11+00:00 2026-05-29T23:13:11+00:00

2>&1 redirect in Bourne shell takes the output sent to a file descriptor 2

  • 0

2>&1 redirect in Bourne shell takes the output sent to a file descriptor 2 (by default, standard error) and sends it instead to file descriptor 1 (by default a standard output).

But what does 2<&1 redirect do?

Does it send stderr to stdin?

My theory was that it was sending stdin to stderr (e.g. same as 1>&2) but experimentally, that is NOT the case:

$ perl -e 'print "OUT\n"; print STDERR "ERR\n"; \
  while (<>) { print "IN WAS $_\n";}'           \
  > out3 2<&1
df
$ cat out3
ERR
OUT
IN WAS df

Note that standard out AND standard error both went to file out3 where stdout was redirected.

  • 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-05-29T23:13:12+00:00Added an answer on May 29, 2026 at 11:13 pm

    The <& operator duplicates an “input” file descriptor. According to IEEE Std 1003.1-2001 (aka Single Unix Specification v3, the successor to POSIX), it’s supposed to be an error to say 2<&1 if 1 is not a file descriptor open for input. However, it appears that bash is lazy and doesn’t care if the file descriptor is open for input or for output.

    So both 2<&1 and 2>&1 simply perform the system call dup2(1, 2), which copies file descriptor 1 to file descriptor 2.

    You can check by running a command like this, since redirections are performed left-to-right:

    sleep 99999 1>/dev/null 2<&1
    

    Then in another window, run lsof on the sleep process. You’ll see that both file descriptors 1 and 2 point to /dev/null. Example (on my Mac):

    :; ps axww | grep sleep
     8871 s001  R+     0:00.01 grep sleep
     8869 s003  S+     0:00.01 sleep 99999
    :; lsof -p 8869 | tail -2
    sleep   8869 mayoff    1w   CHR    3,2       0t0       316 /dev/null
    sleep   8869 mayoff    2w   CHR    3,2       0t0       316 /dev/null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to redirect all of the output of a Bourne shell script
To temporarily redirect stdout to a file, I'm doing: printf(Before); freopen_s(&stream, test.txt, w, stdout);
Though .htaccess, I want to redirect /page/var1/var2 to ./page.php?var1=var1&var2=var2. This is very easy BUT
In AIX, I tried to redirect both STDERR & STDOUT to /dev/null but the
If I do a redirect in action as normal: $this->redirect('@mypage?apple=1&banana=2&orange=3'); ... Symfony produces the
So here is my problem. I want to redirect name.domain.com/trips/1 to domain.com?username=name&trip=1 using modrewrite.
I want to redirect these URLs: http://example.com/search to http://example.com/?page=search http://example.com/search?q=keyword to http://example.com/?page=search&q=keyword I am
(1) a={'b':'bbbb','c':'ccc',....} (2) self.redirect('/tribes/view?b=' + a['b'] + '&c=' + a['c']) so i want to
http://mysite.com/songs/company-name/song-name i want to redirect it to http://mysite.com/songs/index.php?name=company-name&song=song-name i read some articles about that
I'm using https://www.facebook.com/dialog/oauth?client_id={0}&scope=email&redirect_uri={1} but the dialog box says install instead of allow, What do

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.