1

I have a script that looks something like the following.

find /path -type f |
sed -re 'stuff' |
xargs -Ix sh -c '{
  echo "information about x"
  ./exe < x
  read
}'

My goal is to provide each file given to xargs as input to exe. However, I do not want the output of exe to be provided all at once. Instead, I wish to study output of exe for each file, and then continue once I am done studying that output. Hence, I have read.

The problem is, read does not work seem here. Upon executing the script, all output was produced. Are there any suggestions on how one might solve this problem?

Note that I am not looking for a way to sleep the execution of xargs. Rather, I am looking for a way to pause xargs, potentially indefinitely, until the user wishes to continue.

3

You can redirect the input to read from /dev/tty like this:

read reply < /dev/tty

You can accomplish effectively the same results within the shell, without using xargs and without directly executing a new shell to process each file:

find /path -type f |
sed -re 'stuff' |
while IFS= read -r x
do
    echo "information about $x"
    ./exe < "$x"
    read reply < /dev/tty
done

I think you'll find that this method is more efficient (not really an issue in this interactive situation), more portable, requires less syntax, and is easier to read and maintain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.