(9) break (11) Continue (15) export (16) expr (17) printf This program sets the parameter list to the date command’s output and then uses the positional parameter $2 to get at the month.Since the date command is sensitive to the language locale, in reality you would have extracted the name of the month using date +%B. The most commonly used form of the command is set -x, which makes a script display a trace of its currently executing command. (20) Shift
function_name () {
statements
}
foo () { echo JAY;}
The eval command enables you to evaluate arguments. It’s built into the shell and doesn’t normally exist as a separate command. eval is a bit like an extra $: It gives you the value of the value of a variable.
The exec command has two different uses. Its typical use is to replace the current shell with a different program.
The second use of exec is to modify the current file descriptors:
exec 3< afile
This causes file descriptor three to be opened for reading from file afile. It’s rarely used.
The export command creates an environment variable from its parameter that can be seen by other scripts and programs invoked from the current program.
The expr command evaluates its arguments as an expression. It’s most commonly used for simple arithmetic in the following form:
x=`expr $x + 1`
The `` (backtick) characters make x take the result of executing the command expr $x + 1. You could also write it using the syntax $( ) rather than backticks, like this:
x=$(expr $x + 1)
(18) return
(19) set
The set command sets the parameter variables for the shell. It can be a useful way of using fields in commands that output space-separated values.
#!/bin/sh
echo the date is $(date)
set $(date)
echo The month is $2
exit 0
The shift command moves all the parameter variables down by one, so that $2 becomes $1, $3 becomes $2, and so on. The previous value of $1 is discarded, while $0 remains unchanged. If a numerical parameter is specified in the call to shift, the parameters move that many spaces. The other variables, $*, $@, and $#, are also modified in line with the new arrangement of parameter variables.
The trap command is passed the action to take, followed by the signal name (or names) to trap on: