| Text-only | Table of Contents (frame/ no frame) |
| (20) Conditional test examples |
|
case with a pattern:
case $var in/*) echo "starts with /" ;;
`cut`:
if [ "`echo $var | cut -c1`" = "/" ] ; then .
if [ "${var%${var#?}}" = "/" ]; then
if [[ $var = /* ]]; then
The [[...]] syntax is handled internally by the shell and can therefore interpret "wildcard" patterns differently than an external command. An unquoted wildcard is interpreted as a pattern to be matched, while a quoted wildcard is taken literally. The [...] syntax, even if handled internally, is treated as though it were external for backward compatability. This requires that wildcard patterns be expanded to matching filenames.
if [ "${var:0:1}" = "/" ]; then
${varname:start:length}
| flow-control-ex.src last modified Mar 11, 2005 | Introduction | Table of Contents (frame/no frame) |
Printable (single file) |
© Dartmouth College |