Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.5k
  • 205
  • 1.8k
  • 2.3k
Source Link
jamadagni
  • 1.4k
  • 1
  • 12
  • 21

Problem with getting interactive input in while read loop

I was doing something like the following minimal example:

#! /bin/sh

# $1 = file containing list of files to sync
# $2 = source dir ; $3 = target dir

cat "$1" | while read f
do
    cp -i "$2"/"$f" "$3"/"$f"
done

I find that cp -i doesn't wait for my input at all and the loop just runs to the end. Why, and what can be done to fix the situation?