Writing Shell Commands in Natural Language

With GenAI, we can communicate with computers in natural language, and get them to do highly technical things just by asking. The Shelly tool is an example of how we can use OpenAI to create shell commands using natural language.

Writing Shell Commands in Natural Language
👊
Thank you for reading TIDAL SERIES. Please forward on to your friends!

Regardless of where you stand on recent advances in artificial intelligence, particularly generative AI, the reality is that using the technology we can communicate with a computer in natural language and have that computer, that program, write other programs for us based on what we have asked it to do.

Natural language processing (NLP) is what makes this work—the discipline of building machines that can manipulate human language, but doing so in the way that we normally use that language, the way we write, and the way we speak as everyday human beings. This type of communication, speaking, some writing, lack formalization, leaving ample room for ambiguity. Even if you think about how you talk to other people, it can be a very stilted model, where there are no real beginnings and ends to ideas or statements. We don't usually punctuate; there's no way to end a sentence. We also talk to different people and groups in different ways and, of course, in different languages.

To talk to computers, we usually use highly formalized configurations, or programming languages, which have carefully designed rules and, in fact, typically must be complied in some fashion, in that the rules are applied before the programs can be run. But while natural language has rules, those rules are often broken, and even when they are broken, we can still understand what people are saying. Usually.

With GenAI, we can now let it translate our oddly formatted natural language requests into something that a computer can understand and create the more formalized configurations and commands that we can then use in a computing environment.

There are many examples, but one I came across recently is Shelly, which allows you to write terminal (shell) commands in natural language, and like many of these tools that are popping up, it uses OpenAI's ChatGPT 4 API behind the scenes to translate the natural language into a shell command. This is useful in situations where you simply can't remember what command you should use to accomplish something, or potentially how to string CLI actions together to accomplish something.

Example of using shelly from its documentation

Install and Use Shelly

I'm working on a Linux computer, and Shelly's README only describes how to install with brew, which I don't use. But Shelly is Python, so its no problem.

😱
You may want to run shelly in a virtual machine just so that you don't have to worry about any dangerous commands. Otherwise, ensure to review what the LLM returns before running it.
setup shelly in Linux
💡
Note that this will create a ~/.shelly/config.yaml file and directory.

When we run a command through shelly, instead of executing it directly, shelly will open an editor (the nano editor by default) so that you can review the command and make any changes. As soon as you exit this editor, the command will be executed.

shelly how to say hi with bash in editor

Here is what running shelly looks like in terms of results, once the editor is closed.

$./shelly.sh "how to say hi with bash"

For example in this one I don't even spell "much" properly. It doesn't matter, as ChatGPT 4 knows what I mean, and shelly runs the "free -h" command for me.

$./shelly.sh "how muich memory is used"

Natural Language

I think it is important and valuable to be able to use computers with natural language. Some technologists will baulk at this idea because, as technologists, we expect each other to be technical. Often very technical. Talking to a computer in natural language can eliminate the need for specific technical expertise, allowing anyone who can open a terminal session and run Shelly to potentially use a shell, which provides access to a wide range of commands and permutations. (Also, you don't have to use Shelly to get commands; we can just ask OpenAI's ChatGPT or other LLMs in chat mode and copy and paste.)

However, there are problems with this method that we have to be aware of, and this is really what most technologists will be concerned with in terms of using natural langauge and LLMs to do technical things:

  • We don't know what the Large Language Model (LLM) will return in terms of commands. It could be anything; the results are not deterministic. It may return one command in one minute and something completely different in a few minutes. Plus, in the case of OpenAI's ChatGPT, the model is changing behind the scenes.
  • There are no guardrails. It might return a command that doesn't do what we want, or worse, a command that does something dangerous, like deleting files we don't want deleted or changing configurations we don't want changed. We would probably want some knowledge of what a good or bad command is, which brings us back to the need for technical skills. However, people also make mistakes when cutting and pasting commands from the internet. We don't always know what a command will do. A Linux operating system is extremely complex, and we can't always be sure what it's doing. At this point, it may not be advisable to run something like Shelly, especially on an OS instance that cannot be easily discarded.
💂
Regarding guardrails, I see that there is a suggestion in the shelly github issues to use something like https://github.com/binpash/try, which will test a command before actually executing it. These are the kind of guardrails we need, but honestly, not just for ruining the commands we are given for GenAI, but for any unknown command, for example, "curl | bash" install scripts.

Is Everything We Do With Computers Deterministic?

While using LLMs to run commands is, at this point, likely more dangerous than useful, I do believe we consider our computing systems to be more deterministic than they really are—that they are always doing exactly what we would expect them to be doing. There is a lot of randomness in the world of computing. For example, we don't always know exactly what a large distributed system is really up to. Or there is the easy example of cosmic rays flipping bits. Honestly, even knowing what a single, simple Linux workstation is doing is a complex question. For example, is there a strange cronjob setup somewhere, that runs at a random time?

Abundance

To achieve high levels of productivity for our society, I believe we need to make computing abundant, and to do so, we need to be able to use it with natural language, such as expressing our intent in our own words, spelling mistakes, and all, as opposed to running imperative commands.

shelly/README.md at main · paletov/shelly
English to command (AI terminal assistant). Contribute to paletov/shelly development by creating an account on GitHub.

Subscribe to Tidal Series by Curtis Collicutt

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe