http://bash.cyberciti.biz/file-management/shell-script-to-simulate-unix-more-command/如何在bash脚本中使用文件描述符3中的“读取”来读取?
#!/bin/bash
# Write a shell script like a more command. It asks the user name, the
# name of the file on command prompt and displays only the 15 lines of
# the file at a time.
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
counter=1
echo -n "Enter a file name : "
read file
if [ ! -f $file ]
then
echo "$file not a file!"
exit 1
fi
# read file line by line
exec 3<&0
while read line
do
# pause at line no. 15
if [ $counter -eq 15 ]
then
counter=0 # reset counter
echo " *** Press [Enter] key to continue ..."
read -u 3 enterKey
fi
echo $line
((counter++))
done < $file
这模拟多个命令.. 我得到这个错误..
读:26:-u
非法选项确保输入的名称一个文件有超过15行.. 此外我读了“阅读”的手册页,我没有得到像“-u”的选项..
那么,我如何阅读使用“读取”从文件描述符3(这是stdin的副本)。
什么的Bash版本: 接下来的空闲描述符数量将从10 例如开始进行分配? – 2010-01-18 16:18:40