Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Minneapolis, MN

    passing multiple outputs / echos to script that calls other script(s)

    not sure if this is the best place for this or "miscellaneous". anyway...

    i have a script, within, it calls has a read <variable> point. (also) has a (separate) read <variable> point. what i want to be able to do is send the first read variable and the second read variable to the script (for example, y and y)
    echo "enter bleh: "
    read bleh
    if [ $bleh = "y" -o $bleh = "Y" ]
      echo "GOOD: $bleh"
      echo "BAD: no."
    echo "enter blah: "
    read blah
    if [ $blah = "y" -o $blah = "Y" ]
      echo "GOOD: $blah"
      echo "BAD: no."
    echo "blah blah blah"
    when running manually, the steps go fine. it calls bleh, you enter y, it echos, it goes on to the rest of blah, you enter y, it goes on....

    if you take out and do something like
    echo y | ./

    it's also fine

    but if is there (or if there are two read points in the file), then i can't pass two "y"s to the script to have one go to one and the second go to the next

    echo y | (echo y | ./ or anything like that, doesn't work. in fact, although nothing gets sent to the second read point, the second if -o block returns " line x: [: too many arguments"

    i don't know if version matters in this case, but it's rhel 4

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    So indeed. The problem here is that read breaks on newlines. You need to somehow pass it 'y' on two different lines.

    There are two general approaches to this problem.

    If you are always going to be passing the same input, that's what the "yes" command was invented for. Run "man yes" for details.

    If you need to pass different lines, you have two choices:

    1) Put all of your input into a file and call the script using that file for input ("./ < file")
    2) Use a here document (explained at [1])

    [1] Here Documents

Posting Permissions

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