| 1 | #!/bin/bash |
| 2 | # Same as previous example, but with "until" loop. |
| 3 | |
| 4 | if [ -z "$1" ] |
| 5 | then |
| 6 | Filename=names.data # Default, if no filename specified. |
| 7 | else |
| 8 | Filename=$1 |
| 9 | fi |
| 10 | |
| 11 | # while [ "$name" != Smith ] |
| 12 | until [ "$name" = Smith ] # Change != to =. |
| 13 | do |
| 14 | read name # Reads from $Filename, rather than stdin. |
| 15 | echo $name |
| 16 | done <"$Filename" # Redirects stdin to file $Filename. |
| 17 | # ^^^^^^^^^^^^ |
| 18 | |
| 19 | # Same results as with "while" loop in previous example. |
| 20 | |
| 21 | exit 0 |