3

I know I can write bash scripts like:

foo() {
  echo $1;
}

but can I define a function that writes:

foo(string) {
  echo $string;
}

I just can't find my way out of this.

5

The only available form is the first one; see the manual for details.

To use named parameters, the traditional technique is to assign them at the start of your function:

foo() {
  string=$1
  # ...
  echo "${string}"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.