linux – 如何在bash脚本中使用文件描述符3中的“read”读取?
发布时间:2020-05-23 15:38:07 所属栏目:Linux 来源:互联网
导读:http://bash.cyberciti.biz/file-management/shell-script-to-simulate-unix-more-command/ #!/bin/bash# Write a shell script like a more command. It asks the user name, the# name of the file on command p
|
http://bash.cyberciti.biz/file-management/shell-script-to-simulate-unix-more-command/ #!/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
这模拟了更多命令..
确保输入超过15行的文件名称.. 那么,我如何使用文件描述符3(它是stdin的副本)中的“read”来读取. 解决方法尝试read key <&3 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- linux – /etc/pam.d/login和/etc/pam.d/system-
- 如何将时间戳证书添加到Linux上已签名的PE文件?
- 如何在基于ARM的嵌入式Linux系统上进行省电?
- 一个命令创建一个目录和文件里面的linux commad
- DRDB和NFS:是否有任何有效的方法可以使NFS的故障
- linux – 在find -exec中使用basename和full pat
- 获取错误install_driver(Oracle)失败:无法加载’
- linux – 如何检测属于gsm/3g-modem的tty是数据还
- 与memset函数等效的Linux内核是什么?
- linux – RNG比/ dev / random更快但加密有用吗?
热点阅读
