一会儿循环后左尖括号在bash中意味着什么? [英] What does the left angle bracket after a while loop mean in bash?

查看:86
本文介绍了一会儿循环后左尖括号在bash中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容来自RHEL上的/etc/init.d/functions.我试图弄清楚__pids_var_run()函数在遇到此while循环时的作用.

The following is from /etc/init.d/functions on RHEL. I'm trying to figure out what the __pids_var_run() function does when I came across this while loop.

            while : ; do
                    read line
                    [ -z "$line" ] && break
                    for p in $line ; do
                            if [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] ; then
                                    if [ -n "$binary" ] ; then
                                            local b=$(readlink /proc/$p/exe | sed -e 's/\s*(deleted)$//')
                                            [ "$b" != "$binary" ] && continue
                                    fi
                                    pid="$pid $p"
                            fi
                    done
            done < "$pid_file"

有人可以解释while : ; do ; ... done < "$pid_file"的作用吗?更具体地说,done之后的最后一部分,其余部分或多或少都有意义.

Could someone explain what while : ; do ; ... done < "$pid_file" does? More specifically, the last part after done, as the rest of it more or less makes sense.

推荐答案

这意味着循环中从stdin读取内容的任何命令都将从给定文件(例如,代替键盘)中读取.

It means that any command in the loop that reads something from stdin will read from the given file (instead of the keyboard, for example).

尤其是在这种情况下,循环使用read line从stdin读取一行,因此当您从$pidfile重定向时,它将有效地逐行读取文件.

In this case in particular, the loop uses read line to read a single line from stdin, so when you redirect from $pidfile it effectively reads the file line by line.

要进一步了解重定向,请参阅以下推荐的说明性重定向教程. 本Bash指南,由 Lhunath GreyCat .

To further read about redirections, here's an Illustrated redirection tutorial which is recommended by this Bash Guide by Lhunath and GreyCat.

这篇关于一会儿循环后左尖括号在bash中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆