1

(Please, help me adjust title and tags.)

When I run connmanctl I get a different prompt,

enrico:~$ connmanctl
connmanctl>

and different commands are available, like services, technologies, connect, ...

I'd like to know how this thing works.

I know that, in general, changing the prompt can be just a matter of changing the variable PS1. However this thing alone (read "the command connmanctl changes PS1 and returns) wouldn't have any effect at all on the functionalities of the commands line (I would still be in the same bash process).

Indeed, the fact that the available commands are changed, looks to me like the proof that connmanctl is running all the time the prompt is connmanctl>, and that, upon running connmanctl, a while loop is entered with a read statement in it, followed by a bunch of commands which process the the input.

In this latter scenario that I imagine, there's not even need to change PS1, as the connmanctl> line could simply be obtained by echo -n "connmanctl> ".

The reason behind this curiosity is that I'm trying to write a wrapper to connmanctl. I've already written it, and it works as intended, except that I don't know how to properly setup the autocompletion feature, and I think that in order to do so I first need to understand what is the right way to write an interactive shell script.

Enlico
  • 23,259
  • 6
  • 48
  • 102
  • 2
    When you start `connmanctl` without arguments in an interactive terminal, `connmanctl` reads its commands from the terminal. It is running, not `bash`. When you run it with arguments, it interprets a single command using its command line arguments, and then returns to bash. – rici Oct 04 '19 at 21:17
  • Ok, @rici, this is exactly what I meant when I wrote _`connmanctl` is running all the time the prompt is `connmanctl>`_. Thank you for confirming this. – Enlico Oct 05 '19 at 21:09

0 Answers0