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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:47:50+00:00 2026-06-14T00:47:50+00:00

Given a shell script: #!/bin/sh echo I’m stdout; echo I’m stderr >&2; Is there

  • 0

Given a shell script:

#!/bin/sh

echo "I'm stdout";
echo "I'm stderr" >&2;

Is there a way to call that script such that only stderr would print out, when the last part of the command is 2>/dev/null, ie

$ > sh myscript.sh SOME_OPTIONS_HERE 2>/dev/null
I'm stderr

Or, alternatively:

$ > sh myscript.sh SOME_OPTIONS_HERE >/dev/null
I'm stdout

It’s a question at the end of a set of lecture slides, but after nearly a day working at this, I’m nearly certain it’s some sort of typo. Pivoting doesn’t work. 2>&- doesn’t work. I’m out of ideas!

  • 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-14T00:47:52+00:00Added an answer on June 14, 2026 at 12:47 am
    % (sh myscript.sh 3>&2 2>&1 1>&3) 2>/dev/null
    I'm stderr
    % (sh myscript.sh 3>&2 2>&1 1>&3) >/dev/null 
    I'm stdout
    

    Explanation of 3>&2 2>&1 1>&3:

    • 3>&2 means make a copy of file descriptor 2 (fd 2) (stderr), named fd 3 (file descriptor 3). It copies the file descriptor, it doesn’t duplicate the stream as tee does.
    • 2>&1 means that fd 2 of sh myscript.sh becomes a copy of it’s fd 1 (stdout). Now, when myscript writes to it’s stderr (it’s fd 2), we receive it on stdout (our fd 1).
    • 1>&3 means that fd 1 of sh myscript.sh becomes a copy of fd 3 (stderr). Now, when myscript writes to it’s stdout (it’s fd 1), we receive it on stderr (our fd 2).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this Unix shell script: test.sh: #!/bin/sh sleep 2 & sleep 5 & sleep
I have a shell script that is created inside a php script (given full
I have a Bourne shell (/bin/sh) script (for portability) that wants to monitor another
My shell script: #!/bin/bash if [ $# -lt 2 ] then echo $0 :
I have a sh/bash script that needs to call a batch file with parameters
I have created a tcsh shell script as follows: #!/bin/tcsh setenv PATH setenv PATH
I am trying to create a shell script that is able to run the
I wrote a shell script that lets me grep through a directory tree and
I am trying to get a bash script that generates JSDoc for given parameters
I have a shell script script here as below: #!/bin/bash CPUSELECTION=1 386SX off \

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.