Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d95222f

Browse files
No more while
1 parent b187a61 commit d95222f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

‎README.md‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,14 +954,34 @@ do
954954
who | grep johndoe
955955
done
956956
```
957-
This program will keep checking if johndoe every minute and print his info when he logs in. If he is already logged in, or just has just logged in after this program starts, you will have to wait 60 seconds before this program tells you that. It will aslo keep printing johndoe information as long as he is logged in. The next program is more interesting; it keeps looping and checking if johndoe is logged in. Once he is logged in, it prints his info and the loop stops.
957+
This program will keep checking if johndoe every minute and print his info when he logs in. If he is already logged in, or just has just logged in after this program starts, you will have to wait 60 seconds before this program tells you that. It will aslo keep printing johndoe information as long as he is logged in. The next program is more interesting; it keeps looping and checking if johndoe is logged in. Once he is logged in, it prints his info. Grep returns an exti status 0 (true) which signals that the loop stops:
958958
```sh
959959
until who | grep johndoe
960960
do
961961
sleep 60
962962
done
963963
```
964-
964+
- The book goes on in describing a program that keeps track of all system users. A few thing to note:
965+
1. the shell variable `$$` is used to distinguish temporary files (that reside in the `/tmp` directory) based on which processes run them as in `newfile=/tmp/johndoe.$$`. When you print this file in the shell, you'd get something like `johndoe.40301` where 40301 refers to the id of the process running this file.
966+
2. A **forever loop**: can be done with the following
967+
expression:
968+
```sh
969+
while true
970+
do
971+
echo something
972+
sleep 3
973+
done
974+
```
975+
An even shorter and more efficient construct that doesn't use a command from the file system is `:` which can be used this way:
976+
```sh
977+
while :
978+
do
979+
echo something
980+
sleep 3
981+
done
982+
```
983+
3. The PATH is usually fixed in the shell file so that it looks only within that path and nowhere else. This prevents running unwanted programs with the same name as the current one that reside somewhere else in the system. So the path that you specify in your shell file overrides the actual system-wide PATH.
984+
965985
966986
967987

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /