#!/bin/bash

cd "$TMPDIR"
# create data file with 5 lines
seq 5 > data.txt
echo "** file data **"
cat data.txt

echo
echo "** case 1 ( read -u fd ) **"
while read -u 3 line; do
  echo "from file: $line"
  read -p "press enter: " stop
  echo "your input: $stop"
done 3<data.txt

echo
echo "** case 2 ( read <&fd ) **"
while read line <&3; do
  echo "from file: $line"
  read -p "press enter: " stop
  echo "your input: $stop"
done 3<data.txt

echo
echo "** case 3 ( read -u temporal fd ) **"
exec {ifd}<data.txt
while read -u $ifd line; do
  echo "from file: $line"
  read -p "press enter: " stop
  echo "your input: $stop"
done
exec {ifd}<&-
