~/ learn/ comp-325/ cards/ Subroutines that live in memory
1 of 10

A function plus a while/shift driver

A function plus a while/shift driver

Answer

lookup() { grep -i "$1" phones.txt | sort } while [ $# -gt 0 ] do lookup "$1" shift done

The 1 in the call is the script argument; the 1 inside the body is the function argument. Positional parameters are rebound for the duration of a call.

S&K 3e ch13 §13.6–§13.7; function definition, return and local scope from POSIX.1-2024 §2.9.5

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/91c84bee-682d-4907-af94-d9d7d7261d4a/flashcard utf-8 LF