Variable Substitution

Variable values can be accessed and manipulated using variable expansion. Basic expansion is done by preceding the variable name with the $ character. Other types of expansion can be used to return portions or the length of variables, use default or alternate values, assign default or alternate values, and more.

Variable Expansion Format

${variable}value of variable
${#variable}length of variable
${variable:word}value of variable if set and not null, else print word. If: is omitted, variable is only checked if it is set.
${variable:=word}value of variable if set and not null, else variable is set to word, then expanded. If: is omitted, variable is only checked if it is set.
${variable:?}value of variable if set and not null, ...

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.