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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:08:26+00:00 2026-05-12T12:08:26+00:00

(this is indirectly a part of a much larger homework assignment) I have something

  • 0

(this is indirectly a part of a much larger homework assignment)

I have something like

    while read LINE
    do
        stuff-done-to-$LINE
        echo "Enter input:"
        read INPUT
        stuff-done-to-$INPUT
    done < infile

I can’t find a successful way of using the console/default stdin for the second read, instead of the redirected stdin.

Needs to be pure bourne script.

  • 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-12T12:08:26+00:00Added an answer on May 12, 2026 at 12:08 pm

    I believe this is supported in the Bourne shell:

    exec 3<doc.txt
    while read LINE <&3
    do
        stuff-done-to-$LINE
        # the next two lines could be replaced by: read -p "Enter input: " INPUT
        echo "Enter input:"
        read INPUT
        stuff-done-to-$INPUT
    done < infile
    

    Input is alternated between the file and the user. In fact, this would be a neat way to issue a series of prompts from a file.

    This redirects the file “infile” to the file descriptor number 3 from which the first read gets its input. File descriptor 0 is stdin, 1 is stdout and 2 is stderr. You can use other FDs along with them.

    I’ve tested this on Bash and Dash (on my system sh is symlinked to dash).

    Of course it works. Here’s some more fun:

    exec 3<doc1.txt
    exec 4<doc2.txt
    while read line1 <&3 && read line2 <&4
    do
        echo "ONE: $line1"
        echo "TWO: $line2"
        line1=($line1) # convert to an array
        line2=($line2)
        echo "Colors: ${line1[0]} and ${line2[0]}"
    done
    

    This alternates printing the contents of two files, discarding the extra lines of whichever file is longer.

    ONE: Red first line of doc1
    TWO: Blue first line of doc2
    Colors: Red and Blue
    ONE: Green second line of doc1
    TWO: Yellow second line of doc2
    Colors: Green and Yellow
    

    Doc1 only has two lines. The third line and subsequent lines of doc2 are discarded.

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

Sidebar

Related Questions

I have one table like this account_id (INT) inviter_id (INT) Now, logged in user
C# 2008 I have been working on this for a while now, and I
Yes, this is a programming-related question, if a little indirectly. For better or worse,
This question has been asked before at How does Android enforce permissions? . While
this might look silly to you but I am stuck here . I have
This is a completely hypothetical question: let's say I have a database where I
I have a WCF service that uses ODP.NET to read data from an Oracle
We have a Flash app (AS3). This is a desktop application that runs in
(This question is indirectly related to a programming issue I'm having; if you think
So I have this stamp timestamp DEFAULT NOW() ON UPDATE NOW() row on my

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.