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.

1 Answer 1

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}"
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .