
getopts | 667
Bash and Korn
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
before retesting cond. Any one of the expressions may be omitted; a
missing cond is treated as being true.
Examples
Search for a phrase in each odd chapter:
for ((x=1; x <= 20; x += 2))
do
grep $1 chap$x
done
function
function name { commands; }
function name ( ) { commands; }
Define name as a shell function. See the description of semantic
issues in the earlier section “Functions.” The first form is for the
Korn shell, although it may also be used with Bash. The second
form is specific to Bash. Bash does not give different semantics to
functions declared differently; all Bash functions behave the same
way.
Example
Define a function to count files:
$ function fcount {
> ls | wc -l
> }
functions
functions
Korn shell alias for typeset -f. (Note the “s” in the name; function
is a Korn shell keyword.) See typeset later in this listing.
getconf
getconf [name [path]]
ksh93 only. Retrieve the values for parameters that can vary across
systems. name is the parameter to retrieve; path is a filename to test
for parameters that can vary on different filesystem types.
The parameters are defined by the POSIX 1003.1 standard. See the
entry for getconf in Chapter 3.
Example
Print the maximum value that can be held in a C int:
$ getconf INT_MAX
2147483647
getopts
getopts [-a name] string name