Linux   发布时间:2022-05-08  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – 如何在bash脚本中使用文件描述符3中的“read”读取?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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@H_696_3@ 
 

这模拟了更多命令..
我收到这个错误..

确保输入超过15行的文件名称..
另外我读了“阅读”的手册页,我没有得到像“-u”这样的选项..

那么,我如何使用文件描述符3(它是stdin的副本)中的“read”来读取.

解决方法

尝试
read key <&3@H_696_3@

大佬总结

以上是大佬教程为你收集整理的linux – 如何在bash脚本中使用文件描述符3中的“read”读取?全部内容,希望文章能够帮你解决linux – 如何在bash脚本中使用文件描述符3中的“read”读取?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: