/ languages / shellscript.html

Table of content

Variables

Templates


Details

Variables

sh.endl="$str.unix.endl"
End of line character for UNIX shell scripts

Default value: $str.unix.endl

Templates

sh.block(indent="true()", content, addFinalEndl="true()")

UNIX shell script code block (Indented code block)
  1. indent
    Indent the content if true (the default)
    Default value: true()
  2. content
    Code snippet
  3. addFinalEndl
    Add a End-of-line at end of block
    Default value: true()

UNIX shell comment block
  1. content
    Comment text
    Default value: .
sh.local(name, interpreter="sh", value, quoted="'auto'")

UNIX shell local variable definition
  1. name
    Variable name
  2. interpreter
    Interpreter type
    Default value: sh
  3. value
    Variable initial value
  4. quoted
    Indicates if the value value have to be quoted. Expect a boolean or the special value 'auto'
    Default value: 'auto'

Attempt to transform a string into a valid identifier name (variable, function)
  1. name

UNIX shell variable call
  1. name
    Variable nmme
  2. index
    Treat the variable as an array and retrieve the $index element (not compatible with all shells)
  3. start
    Retrieve a substring of the variable content starting at offset $start (not compatible with all shells)
  4. length
    Retrieve a substring of $length character of the variable content (not compatible with all shells)
  5. quoted
    Add quotes around
    Default value: false()
sh.varLength(name, quoted="false()")

Create the expression to retrieve a variable value length (${#var})
  1. name
    Variable name
  2. quoted
    Add quotes around
    Default value: false()

Operations on itself
  1. name
    Variable name
  2. operator
    Operator
    Default value: '+'
  3. value
    Second operand
    Default value: 1

Treat the variable as an integer value and increment its value
  1. name
    Variable name
  2. value
    Increment value
    Default value: 1

Create the expression to retrieve an array element count (not compatible with all shells)
  1. name
    Variable name

Set an element of an array variable (not compatible with all shells)
  1. name
    Variable name
  2. index
    Array index
  3. value
    Element value

Append a new element to an array variable
  1. name
    Variable name
  2. value
    New element value
  3. startIndex
    First element of the array (depends on interpreter type)
    Default value: 0
sh.arrayCopy(from, to, indexVariableName="'i'", append="true()", interpreter="'sh'", declareLocal="false()")

Copy array elements to another variable (not compatible with all shells)
  1. from
    Input variable name
  2. to
    Output variable name
  3. indexVariableName
    Name of the index variable used in loop
    Default value: 'i'
  4. append
    Default value: true()
  5. interpreter
    UNIX shell interpreter type
    Default value: 'sh'
  6. declareLocal
    Declare temporary variable as local variable
    Default value: false()

Iterate through array elements
  1. name
    Array variable name
  2. elementVariableName
    Variable representing the current element
    Default value: 'i'
  3. interpreter
    UNIX shell interpreter type
    Default value: 'sh'
  4. declareLocal
    Declare temporary variable as local variable
    Default value: false()
  5. do

UNIX shell function definition (not compatible with all shells)
  1. name
    Function name
  2. content
    Function body
  3. indent
    Indicates if the function body have to be indented
    Default value: true()
  4. interpreter
    UNIX shell interpreter type
    Default value: 'sh'

While statement
  1. condition
    Condition
  2. do
    Loop code
  3. indent
    Default value: true()
sh.for(condition, do, indent="true()")

For statement
  1. condition
    For condition
  2. do
  3. indent
    Indent *do* block
    Default value: true()
sh.incrementalFor(variable="i", init="0", operator="'<'", limit, increment="1", do, indent="true()", interpreter="'sh'", declareLocal="false()")

for (i=start;i<stop;i++)
  1. variable
    Default value: i
  2. init
    Default value: 0
  3. operator
    Default value: '<'
  4. limit
  5. increment
    Default value: 1
  6. do
  7. indent
    Default value: true()
  8. interpreter
    UNIX shell interpreter type
    Default value: 'sh'
  9. declareLocal
    Declare temporary variable as local variable
    Default value: false()
sh.if(condition, then, else, indent="true()", shortForm="true()")

IF statement
  1. condition
    Condition
  2. then
    Code to execute if the condition is true
  3. else
    Code to execute if the condition is false
  4. indent
    Indent 'then' and 'else' blocks
    Default value: true()
  5. shortForm
    When possible, use the short form [ {condition} ] && {then}
    Default value: true()
sh.case(case, in, indent="true()")

CASE statement
  1. case
    Case variable name
  2. in
    Case body
  3. indent
    Default value: true()
  1. case
  2. content
  3. indent
    Default value: true()

Escape a string literal
  1. value
  2. quoteChar
    Value to escape. Assumes the given parameter does not already contains any escaped character
    Default value: "'"
  3. evaluate
    Enclosing quotes character
    Default value: false()

1>/dev/null 2>&1
sh.chunk.arrayValueExists(name, value, interpreter="'sh'", declareLocal="false()", onExists="'return 0'", otherwise="'return 1'")

Check if a value exists in array elements.
  1. name
    Array variable name
  2. value
    Value to check
  3. interpreter
    UNIX shell interpreter type
    Default value: 'sh'
  4. declareLocal
    Declare temporary variable as local variable
    Default value: false()
  5. onExists
    What to do if value exists
    Default value: 'return 0'
  6. otherwise
    What to do if value does not exists
    Default value: 'return 1'