Re: bash subroutine syntax question



On Oct 31, 9:21 am, ToddAndMargo <ToddAndMa...@xxxxxxxxxxxxxxxxxx>
wrote:
Hi All,

Just a trivia question.  In bash subroutines

           My Subroutine () {

The blank in the name My Subroutine causes a syntax error. It's good
that you already corrected it in later posts.

           ...
           }

Does anything go inside the "()"?


There's an alternative way to compose a function header. The shell
function doesn't require its formal parameters to be listed when it's
defined. See

$ man sh

for more.

$ cat a.sh
#!/bin/sh

f1()
{
echo f1: arg num: $#, args: $*
}

function f2
{
echo f2: arg num: $#, args: $*
}

f1 $*
f2 $*

$ sh a.sh aa bb
f1: arg num: 2, args: aa bb
f2: arg num: 2, args: aa bb
$
.