Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

Executing stdout results line by line that has a prompt confirmation

$
0
0

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:

  1. Using expect script.
  2. 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 or no 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.


Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>