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

  • Home
  • SEARCH
  • 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 6677951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:11:06+00:00 2026-05-26T04:11:06+00:00

I am pretty sure I’ve seen this done before, but I can’t seem to

  • 0

I am pretty sure I’ve seen this done before, but I can’t seem to find it by google.

for file in $mydir/*
do
    #redirect the rest to $myotherdir/$file.output.
    echo this should go to the $myotherdir/$file.output.
done

It would also be great if I could use tee instead of a redirect, so that it goes to that file and stdout.

  • 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-26T04:11:06+00:00Added an answer on May 26, 2026 at 4:11 am

    You can use any of at least three techniques. One is illustrated by dtmilano‘s answer, using a full sub-shell and parentheses, but be careful about clobbering previous output:

    outfile=/$myotherdir/$file.output
    
    for file in $mydir/*
    do
        (
        ...commands...
        ) >> $outfile
        ...other commands with output going elsewhere...
    done
    

    Or you can use braces to group the I/O redirection without starting a sub-shell:

    outfile=/$myotherdir/$file.output
    
    for file in $mydir/*
    do
        {
        ...commands...
        } >> $outfile
        ...other commands with output going elsewhere...
    done
    

    Or you can sometimes use exec:

    exec 1>&3    # Preserve original standard output as fd 3
    outfile=/$myotherdir/$file.output
    
    for file in $mydir/*
    do
        exec 1>>$outfile
        ...standard output
        exec 1>&3
        ...other commands with output going to original stdout...
    done
    

    I’d normally use the { ... } notation, but it is cranky in a 1-line scenario; the } must appear where a command could start:

    { ls; date; } >/tmp/x37
    

    The second semicolon is needed there.

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

Sidebar

Related Questions

I pretty sure I've seen this somewhere but I can't seem to find it
Pretty sure there is an easy answer to this, but just can't find the
I am pretty sure this has been answered before but I cannot seem to
I'm pretty sure this is a basic question, but I can't find the answer
I'm pretty sure this can't be done in Oracle, but I'd love to be
I'm pretty sure I've done this before, but I've forgotten how. Here's the problem:
I am pretty sure I have seen this before, but I haven't found out
I'm pretty sure this can be done without going into a function but I
I am pretty sure there is and answer out there.. But I can't seem
I'm pretty sure it has been asked before, but I could not find anything

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.