Text-only Table of Contents (frame/ no frame)
(22) Manipulating Variables Previous Top Next

Manipulating Variables (ksh/bash only)

Text variables

The pattern in the following uses the same wildcards as for filename matching.
returns the length of $var in characters
removes the shortest suffix of $var patching pattern
removes the longest suffix of $var patching pattern
removes the shortest prefix of $var patching pattern
removes the longest prefix of $var patching pattern

Numeric variables

$(( integer expression ))
The $(( ... )) construction interprets the contents as an arithmetic expression (integer only). Variables are referenced by name without the "$". Most of the arithmetic syntax of the 'C' language is supported, including bit manipulations (*,/,+,-,|,&,<<,>>. Use parentheses for changing precedence).
filename is set to "datafile.dat" since the longest prefix pattern matching "*/" is the leading directory path (compare basename)
path is set to "/data/public/project/trials/set1" since the shortest suffix pattern matching "/*" is the filename in the last directory (compare dirname)

often used in while loops

Previous Top Next

variable-manipulation.src  last modified Feb 11, 2005 Introduction Table of Contents
(frame/no frame)
(single file)
© Dartmouth College