Results 1 to 6 of 6

Thread: Mass redirection problem

  1. #1

    Mass redirection problem

    Its me again. Question of the day: how do you redirect all of the output for a chunk of code? FIrst off, note this piece of code that works:

    while true
      echo "Please answer y or n: "
      read answer
      case $answer in
        [yYnN]) ;;
                 *) echo "you did not answer with a y or n. Please try again.
    If i want to redirect all of the output to the terminal i should be able to just add "> `tty`" after the "done" at the end of the while loop right? So it looks like this:

    while true
    case statement
    done > `tty`

    But this does not work. What happens is that it outputs the first line of output within the while loop, accepts input from the user, then exits the loop... just because i added a "> `tty`" after the done. Does anyone have any idea what is going on?

    Thanks for any help! I posted the same question at linux newbie and it was a tad more detailed. Here is the link if youd like to see the question there:

  2. #2

    Re:Mass redirection problem

    bash-2.05a$ ./ > `tty`
    Please answer y or n: 
    you did not answer with a y or n. Please try again.
    Please answer y or n: 
    As you can see, it seems to work in FreeBSD. Do note that you left out a quotation mark after the echo command though.

  3. #3

    Re:Mass redirection problem

    Well, the quotation is there in my script. I just whipped that up really quick to give an example. Did you run that exact code? Did you redirect the whole script's output or just the while loop? Or even just the case statement? Im running this in sh but im not sure that would have anything to do with it. Thanks for checking it out!


  4. #4

    Re:Mass redirection problem

    I copied and pasted your exact code and just added a quotation mark. And just look for yourself what it outputted. I copied and pasted that too.

  5. #5

    Re:Mass redirection problem

    It turns out that it is in fact an old bug with sh. I wrote this script in bash and ran it on a system that was running sh because i figured it would work the same because i didnt try anything really advanced. Well, there is a bug with sh where if you try to redirect a whole statement like that in a loop, if, or case statement it does not break, continue, or exit correctly.

    Someone found this link for me that sums it up (notice when it was posted! hahah!):

  6. #6

    Re:Mass redirection problem

    Good lord! That post was in 1988, yet he still says the bug is ancient. Man, that's old school.

Similar Threads

  1. Redirection mystery
    By simusphere in forum Linux - General Topics
    Replies: 5
    Last Post: 12-06-2008, 09:35 PM
  2. Redirection of
    By mechdave in forum General Chat
    Replies: 1
    Last Post: 10-22-2008, 01:32 PM
  3. weapons of mass destruction
    By GhostDawg in forum General Chat
    Replies: 4
    Last Post: 04-13-2004, 12:43 PM
  4. Digital Camera as usb mass storage
    By _nmk in forum Linux - General Topics
    Replies: 3
    Last Post: 02-26-2003, 04:37 PM
  5. Apache 2.0 moves into mass release
    By cloverm in forum Linux - Hardware, Networking & Security
    Replies: 1
    Last Post: 04-09-2002, 05:52 PM


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts