O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required