1

I am looking for a solution like what is posted in the following question:

Get a list of function names in a shell script

But which works in a POSIX shell script. And if it is not possible, then at least something that works in dash.

I have the same scenario as him: I am making a help screen for a script whose first argument is a function and succeeding arguments are parameters of that function.

Since the script is under active development, I want the help screen to be automatically updated whenever I add a new "command" under the script.

Some functions are internal, and I solved that by putting a pattern in the function name if it is callable as a command from the script. Once I get the list of functions in my script it would be simple to grep out the ones containing that pattern so I can list them in the help screen.

bamm
  • 111
  • 2
  • If it's all within your script then the `grep "()"` from the duplicate should work, perhaps with some cleanup processing. – tripleee Oct 30 '20 at 06:15
  • Thanks for the tip, since the "function" keyword mentioned in the duplicate is not allowed in dash and everyone in that question was assuming bash. I tried it and it almost works. How do I get rid of grep grepping itself? The line containing `grep "()"` also shows up in the search for `()`. – bamm Oct 30 '20 at 08:03
  • The standard trick is to use a regex which doesn't match itself, like `grep '[(])'` – tripleee Oct 30 '20 at 08:09

0 Answers0