Sha256: e87a31e712a1ad69695f53fe3c69517bcdbea8d6ca3ed0385e4e71861bf851b9

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

function test {
  # `$@` is an array of all the args?
  echo "$@";
}

# test 1 2 3

# definitions
# -----------

RUN_DEFS=1
if [[ "$RUN_DEFS" -ne "0" ]]; then

  # both seem to work fine in bash and sh
  #
  # function keyword style:
  function test1 {
    echo "test1 called"
  }
  test1

  # empty args style:
  test2 () {
    echo "test2 called"
  }
  test2

  # you can add empty args to the keyword style: 
  function test3 () {
    echo "test3 called"
  }
  test3

  # but you must have the empty args without the keyword,
  # this does not work in bash or sh:
  # test4 {
  #   echo "test4 called"
  # }
  # test4

  # i kinda like the function keyword style 'cause i don't think you can
  # put argument names in the empty args list, so it's kinda confusing
  #
  # doesn't work:
  # test5 (X, Y) {
  #   echo $X
  #   echo $Y
  # }
  # test5 "hey" "ho"

fi

# function names
# --------------

RUN_NAMES=0
if [[ "$RUN_NAMES" -ne "0" ]]; then

  # dots in names work fine in bash, but fail in sh 'cause
  # the '.' makes in an invalid identifier. i don't have internet right now,
  # but i *think* that '_' was the only seperator legal in an sh function name
  function names.1 {
    echo "names 1 called"
  }
  names.1

  names.2 () {
    echo "names 2 called"
  }
  names.2

  # in sh, would need to do something like
  function names__3 {
    echo "names 3 called"
  }
  names__3

  # ugh

fi

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nrser-rash-0.2.3 dev/scratch/functions.sh
nrser-rash-0.2.2 dev/scratch/functions.sh
nrser-rash-0.2.1 dev/scratch/functions.sh
nrser-rash-0.2.0 dev/scratch/functions.sh