Variable Substitution

   

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

Table of Contents
Appendix G.  Pdksh Quick Reference


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:?/span>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, else print "variable: parameter null or not set". If: is omitted, variable is only checked if it is set.

${variable:?word}

value of variable if set and not null, else print value of word and exit. If: is omitted, variable is only checked if it is set.

${variable:+word}

value of word if variable is set and not null, else nothing is substituted. If: is omitted, variable is only checked if it is set.

${variable#pattern}

value of variable without the smallest beginning portion that matches pattern

${variable##pattern}

value of variable without the largest beginning portion that matches pattern

${variable%pattern}

value of variable without the smallest ending portion that matches pattern

${variable%%pattern}

value of variable without the largest ending portion that matches pattern


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net