What does the left angle bracket after the while loop in bash mean?

The following are the functions of /etc/init.d/functions on RHEL. I am trying to understand what the __pids_var_run() function __pids_var_run() when I come 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" 

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

+5
source share
2 answers

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

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

To further read about redirects, here's an illustrated redirection guide that is recommended is the Lhunath and GrayCat Bash Guide .

+4
source

I see that this quesiton has already answered (I cannot comment because I have done generosity), but I think you should check this site when you have a chance:

http://mywiki.wooledge.org/BashFAQ/001

This guy (or girl) is really immersed in the correct and inappropriate syntax with examples.

+3
source

Source: https://habr.com/ru/post/1244603/


All Articles