I have a command that (potentially) prints several lines and then I want to execute them one by one (using xargs
for example, or anything else):
find . -name "*string*" -print | awk '{ print "echo " $1 " >> file.txt" }' | xargs -L 1
Execution of each of the echo ... >> file.txt
commands will give a prompt Enter a value:
where the user has to explicitly type yes
for confirmation or no
to cancel further execution of the command.
Is it possible to pipe this into one line to always enter yes
for example? Or halt until user enters yes?
So far I'm thinking of 2 possible solutions:
- Using expect script.
- Capturing stdout of the executed command line by line, and looping over
those lines until I reach the prompt, then either waiting for user
input or adding
yes
orno
automatically.
Is there an easier way to do this and piping an extra command after xargs
? (Let say if I always want to enter yes
?).
Which of the above solutions would be better. I would assume the second one would be preferable to ensure cross-platform compatibility and avoiding external dependencies like expect
.