#!/bin/bash getcommands() { local command command="$*" if ! test "$command" = "help"; then ./esctl $command -h | sed -e '/^COMMANDS:/,/^$/!d;//d' -e 's/^ //' -e 's/[, ].*//' | sort fi } printcommands() { local indent basecommand commands command indent="$1" basecommand="$2" commands="$3" for command in $commands; do echo "$indent" "$command" commands=$(getcommands $basecommand $command) if test -n "$commands"; then printcommands "${indent} " "$basecommand $command" "$commands" fi done } commands=$(getcommands "") printcommands "" "" "$commands"