linux-tutorial/codes/shell/示例脚本/输入和输出/创建自己的重定向/创建输入文件描述符.sh

23 lines
332 B
Bash

#!/bin/bash
# redirecting input file descriptors
exec 3>&1
echo "This is the 3 file descriptor" >&3
exec 6>&0
exec 0<test
count=1
while read line
do
echo "Line #$count: $line"
count=$[ $count+1 ]
done
exec 0<&6
read -p "Are you done now?" answer
case $answer in
Y|y) echo "Goodbye";;
N|n) echo "Sorry, this is the end";;
esac