The source code of bash has a routine to output the

This preview shows page 520 - 523 out of 598 pages.

####The source code of Bash has a routine to output the#+ [subscript]=valuearray assignment format.#As of version 2.05b, that routine is not used,#+ but that might change in future releases.# The length of a string, measured in non-null elements (characters):echoecho '- - Non-quoted references - -'echo 'Non-Null character count: '${#VarSomething}' characters.'# test='Lit'$'\x00''eral'# $'\x00' is a null character.# echo ${#test}# See that?#The length of an array, measured in defined elements,#+ including null content elements.echoecho 'Defined content count: '${#ArrayVar[@]}' elements.'# That is NOT the maximum subscript (4).# That is NOT the range of the subscripts (1 . . 4 inclusive).# It IS the length of the linked list.####Both the maximum subscript and the range of the subscripts may#+ be found with additional script programming.# The length of a string, measured in non-null elements (characters):echoecho '- - Quoted, Glob-Pattern references - -'echo 'Non-Null character count: '"${#VarSomething}"' characters.'#The length of an array, measured in defined elements,#+ including null-content elements.echoecho 'Defined element count: '"${#ArrayVar[*]}"' elements.'#Interpretation: Substitution does not effect the ${# ... } operation.#Suggestion:#Always use the All-Elements-Of character#+ if that is what is intended (independence from IFS).#Define a simple function.#I include an underscore in the name#+ to make it distinctive in the examples below.####Bash separates variable names and function namesAdvanced Bash-Scripting GuideAppendix A. Contributed Scripts515
#+ in different namespaces.#The Mark-One eyeball isn't that advanced.###_simple() {echo -n 'SimpleFunc'[email protected]#Newlines are swallowed in}#+ result returned in any case.# The ( ... ) notation invokes a command or function.# The $( ... ) notation is pronounced: Result-Of.# Invoke the function _simpleechoecho '- - Output of function _simple - -'_simple# Try passing arguments.echo# or(_simple)# Try passing arguments.echoecho '- Is there a variable of that name? -'echo $_simple not defined# No variable by that name.# Invoke the result of function _simple (Error msg intended)###$(_simple)# Gives an error message:#line 394: SimpleFunc: command not found#---------------------------------------echo####The first word of the result of function _simple#+ is neither a valid Bash command nor the name of a defined function.#### This demonstrates that the output of _simple is subject to evaluation.#### Interpretation:#A function can be used to generate in-line Bash commands.# A simple function where the first word of result IS a bash command:###_print() {echo -n 'printf %q '[email protected]}echo '- - Outputs of function _print - -'_print parm1 parm2# An Output NOT A Command.echo$(_print parm1 parm2)#Executes: printf %q parm1 parm2#See above IFS examples for the#+ various possibilities.echo$(_print $VarSomething)# The predictable result.echoAdvanced Bash-Scripting GuideAppendix A. Contributed Scripts516
# Function variables# ------------------echoecho '- - Function variables - -'# A variable may represent a signed integer, a string or an array.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 598 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
Kushagra
Tags
Beowulf, Shell, Kubla Khan, scripting language, Shell script, C shell

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture