Shell functions, discussed in Chapter 26.
- Two different, equivalent syntaxes.
function func1 {
commands
}
func2 () {
commands
}
- The brackets need to be on lines as shown.
- The parens are just markers; you never list parameters.
- You can't return values in anything like familiar languages.
- Can be created in scripts or from the command line.
- Invoked like commands.
- Type the name of the function to run it.
- If you send parameters, they are available as $1, $2,
etc.
- The return command produces a exit code available through $?,
not an assignable return value.
- The usual way to get data back is through printing it, then
VAR=$(command).
- Local variables.
- Inside a function, local vname
- This will now belong only to the function.
- Other variables are global.