The problem with redirecting to a file or using a subshell or similar technique is that the yes command is infinite. There is no terminating condition other than killing the process. There are ways to do this with other commands but something like yes is going to be problematic.
Is yes a requirement or did you serve it up as an example of what you are trying to do?
L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
The problem, I believe, is not how to limit the output of yes; you've clearly demonstrated how to do that. I think the more difficult problem is doing that without using a pipe (thus preventing a 'broken pipe' from terminating yes).
L7Sqr
Practically a Posting Shark
851 posts since Feb 2011
Reputation Points: 253
Solved Threads: 155
Skill Endorsements: 7
You can easily embed the output from a shell command into the argument list of another command using backquotes. Example, if you want 'y' to be passed as the option "--accept=", try this:
command --accept=`yes | head -1`
To get that into the standard input stream you can do this (scripting is best since it requires at least 2 lines):
command <<EOF y
EOF
# or
command <<EOF `yes | head -1`
EOF
rubberman
Posting Maven
2,581 posts since Mar 2010
Reputation Points: 365
Solved Threads: 307
Skill Endorsements: 52