Results 1 to 2 of 2
not sure if this is the best place for this or "miscellaneous". anyway... i have a script, blah.sh. within, it calls bleh.sh. bleh.sh has a read <variable> point. blah.sh (also) ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-01-2012 #1
- 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, blah.sh. within, it calls bleh.sh. bleh.sh has a read <variable> point. blah.sh (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 blah.sh script (for example, y and y)
#!/bin/sh echo "enter bleh: " read bleh if [ $bleh = "y" -o $bleh = "Y" ] then echo "GOOD: $bleh" else echo "BAD: no." fi
#!/bin/sh ./bleh.sh echo "enter blah: " read blah if [ $blah = "y" -o $blah = "Y" ] then echo "GOOD: $blah" else echo "BAD: no." fi echo "blah blah blah"
if you take out bleh.sh and do something like
echo y | ./blah.sh
it's also fine
but if bleh.sh 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 | ./blah.sh) or anything like that, doesn't work. in fact, although nothing gets sent to the second read point, the second if -o block returns "blah.sh: line x: [: too many arguments"
i don't know if version matters in this case, but it's rhel 4
- 05-03-2012 #2
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 ("./blah.sh < file")
2) Use a here document (explained at )
 Here Documents