Skip to main content
Explanation
Source Link
Luchostein
  • 621
  • 5
  • 8

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}

EDIT: Beware of special characters into your metadata. For pure text, you can use:

: <<EOT
Your metadata text here.
EOT

EDIT: You may use instead a global associative array to store all function's metadata:

declare -A METADATA=()
METADATA[fun1]='foo bar'
function fun1() {
  echo I have some metadata: "${METADATA[$FUNCNAME]}"
}
METADATA[fun2]='baz you'
function fun2() {
  echo I have some other metadata: "${METADATA[$FUNCNAME]}"
}

This way, you don't need to parse declare or type's output, but only query for an array's key.

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}

EDIT: Beware of special characters into your metadata. For pure text, you can use:

: <<EOT
Your metadata text here.
EOT

EDIT: You may use instead a global associative array to store all function's metadata:

declare -A METADATA=()
METADATA[fun1]='foo bar'
function fun1() {
  echo I have some metadata: "${METADATA[$FUNCNAME]}"
}
METADATA[fun2]='baz you'
function fun2() {
  echo I have some other metadata: "${METADATA[$FUNCNAME]}"
}

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}

EDIT: Beware of special characters into your metadata. For pure text, you can use:

: <<EOT
Your metadata text here.
EOT

EDIT: You may use instead a global associative array to store all function's metadata:

declare -A METADATA=()
METADATA[fun1]='foo bar'
function fun1() {
  echo I have some metadata: "${METADATA[$FUNCNAME]}"
}
METADATA[fun2]='baz you'
function fun2() {
  echo I have some other metadata: "${METADATA[$FUNCNAME]}"
}

This way, you don't need to parse declare or type's output, but only query for an array's key.

EDIT with more alternatives
Source Link
Luchostein
  • 621
  • 5
  • 8

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}

EDIT: Beware of special characters into your metadata. For pure text, you can use:

: <<EOT
Your metadata text here.
EOT

EDIT: You may use instead a global associative array to store all function's metadata:

declare -A METADATA=()
METADATA[fun1]='foo bar'
function fun1() {
  echo I have some metadata: "${METADATA[$FUNCNAME]}"
}
METADATA[fun2]='baz you'
function fun2() {
  echo I have some other metadata: "${METADATA[$FUNCNAME]}"
}

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}

EDIT: Beware of special characters into your metadata. For pure text, you can use:

: <<EOT
Your metadata text here.
EOT

EDIT: You may use instead a global associative array to store all function's metadata:

declare -A METADATA=()
METADATA[fun1]='foo bar'
function fun1() {
  echo I have some metadata: "${METADATA[$FUNCNAME]}"
}
METADATA[fun2]='baz you'
function fun2() {
  echo I have some other metadata: "${METADATA[$FUNCNAME]}"
}
Source Link
Luchostein
  • 621
  • 5
  • 8

You can use the nop builtin :. Besides, you don't need to store it as a variable:

function f() {
  : your metadata here
  : "or here"
  # do yours
}