function example { args : string firstName , string lastName , integer age } {
echo "My name is ${firstName} ${lastName} and I am ${age} years old."
}
example test1 test2 test3
function example {
args
: @required string firstName
: string lastName
: integer age
: string[] ...favoriteHobbies
echo "My name is ${firstName} ${lastName} and I am ${age} years old."
echo "My favorite hobbies include: ${favoriteHobbies
[li]}"[/li]
}
If you have ***args ***defined that can handle/parse the arguments then sure, otherwise the error message is correct. There is nothing in your path (an executable or a function, alias or a builtin) that has the name ***args ***. Also the first function in the above example should be avoided since it is not documented, while it may work because it is still a compound command it is not easy to read or understand by someone who is reading your code, unless of course you’re code golfing…
I’ve checked through some old documentation (books – paper) – “UNIX for the impatient”; “UNIX System V”; “O’Reilly Bash”; – and, there’s no mention of the following StackOverflow function syntax:
function name { «named parameters» } { «commands» }
In other words, this syntax seems to have never been part of the Bash definition.
It may well be that, at some stage in the Bash development, there were a couple of Bash versions limited to one or two special sites, located in some country or another, which may have supported this function syntax relating to named function parameters but, it seems that, the part of this planet with those special Bash versions has, disappeared
…
If you prefer named parameters, it’s possible (with a few tricks) to actually pass named parameters to functions (also makes it possible to pass arrays and references).
And yes, it’s part of the “Bash Infinity” framework – last change in GitHub over a year ago – last change on the “Invent Life” web site: 2015 …
Yes, it was an interesting attempt to move Bash into the O-O world, but …
There ain’t a package for this in the openSUSE repositories and, DuckDuckGo searching for an RPM package anywhere doesn’t result in anything except the GitHub entry …
When one looks for constructs found in proper programming languages, my limited experience with bash tells me it would be time to switch to a proper programming language. Python 3.x should be omnipresent these days.
Whether or not Object-Oriented programming is “better than” programming which is not O-O has been long discussed, and criticised – since the idea of O-O first appeared …
Yes, Python is O-O, as is Perl and, Ruby and, … – the list is long …
Even Fortran is O-O these days – as of Fortran 2003 …
Bottom line:
Bash ain’t O-O – C also not …
If you want an O-O scripting language, you have a large number of choices to choose from – Bash ain’t one of them …