Creating a bash based restricted shell

Hello.

I need to write a command line interface that can be invoked either directly from the shell (command sub-command arguments), or as a shell that can process sub-commands.
i want to use bash auto completion for both scenarios.

example: lets say my CLI module is called 'mycli' and there are 3 sub commands: add, list, delete.

for the first type of usage, one would write from the prompt:

ubuntu@ubuntu:/$mycli add -name myname 

for the second type of usage, one would do the following:

ubuntu@ubuntu:/$mycli
MYCLI>add -name myname
MYCLI>list

i know how to create a bash autocomplete for the first example. but don't know how to create a shell-like prompt that will use bash auto complete for sub command processing.

any suggestions?

bash uses the readline library to implement the auto complete, line up, emacs keys editing in commands.

There is a Perl "scriptable" equivalent, Term::Readline which may provide a suitable easily programmable shell for you

1 Like

unfortunately, although the readline library would probably work, it's license mandates that any software using it will be free. and the product i'm developing isn't, so i probably can't use it.

any other suggestions?

Hi.

The tcl/tk package may be of some use. The sense of the license is left as an exercise: Tcl/Tk Licensing Terms

Searching for completion at the tcl/tk site brings up a about 2K hits.

Best wishes ... cheers, drl

If readline would work, but its license is a dealbreaker, have a look at the editline library (BSD license).

Regards,
Alister

Hi, Alister.

Good alternative for many features. However, at a quick glance I didn't see anything for completion. I looked at editline(3) - Linux man page and Man Page for editline (freebsd Section 3) - The UNIX and Linux Forums -- is there a betteer version or did I just miss reading the page? ... cheers, drl