How I wrote a BASH script using OpenAI’s ChatGPT

The writer created a Bash script using OpenAI’s ChatGPT and provided some tips for others who may want to try it. They found the tool to be useful for quickly generating scripts, but also noted some limitations. A complete Bash script generated by ChatGPT with guidance from the writer is provided.

In 2008, I became interested in learning programming and decided to start teaching myself PHP. Over the next five years, I was able to use my self-taught skills to create several websites for different clients. After that, I transitioned to backend development using Codeigniter and worked on that for a few years.

Eventually, I discovered Laravel and fell in love with its powerful features and elegant syntax. Since then, I have been working exclusively on Laravel backend development projects.

Despite my expertise in web development, I have no experience with machine learning algorithms. However, I have always been fascinated by the field and the potential it holds to improve various industries. Recently, I came across ChatGPT and was intrigued by its ability to generate natural language responses in a conversation.

In this post, I will share my experience using ChatGPT to create a Bash script as a PHP Backend developer. ChatGPT is a powerful language model developed by OpenAI that can generate human-like text based on a given prompt. As a PHP Backend developer, I was curious to see if ChatGPT could assist me in writing Bash scripts more efficiently. In this article, I will explain how I used ChatGPT and what I learned from the experience.

I initially found it challenging to use ChatGPT to create a complete Bash script. I struggled with timeouts in the responses, but with patience and guidance, I was able to successfully use ChatGPT to generate a script that met my needs, complete with comments and error handling. I was impressed by the level of detail and accuracy in the generated script.

However, I also discovered some limitations of using ChatGPT for Bash scripting. In some cases, the generated code did not match my preferred style and required some manual editing. Additionally, ChatGPT was not always able to provide suggestions for more complex tasks or edge cases.

Despite these limitations, I found ChatGPT to be a valuable tool for quickly generating Bash scripts and providing useful suggestions. In this post, I will share the steps I took to use ChatGPT as a PHP Backend developer and provide some tips for others who may want to try it for themselves.

Here is the complete bash script generated by ChatGPT with guidence by my as a PHP developer.

It looks like the script is well-written and follows best practices for Bash scripting. The script is well-documented, with comments that explain each step of the process and the reasoning behind it. The script also uses regular expressions to validate the input and checks for root permissions before running. It also uses error handling to gracefully exit the script if any errors occur. Overall, it appears that ChatGPT was able to assist in the creation of a well-written Bash script.

Here is a list of queries I made to ChatGPT

  1. How can I setup UFW to allow my dynamic IP address every time it changes?
  2. My IP address changes very often.
  3. I don’t have a specific IP range, every time the IP is totally different and I cannot allow free access to port 22.
  4. The dynamic DNS service sounds like a great idea. How would I set this up?
  5. I want to accomplish this by using a Bash script.
  6. I don’t want to use a client. I got a hostname that points to by IP address. How can I use this hostname in a bash script to update UFW rules to gain access to port 22?

Each of my questions led me to the next, and by following this step-by-step approach, I was able to obtain the Bash script above.

I found that ChatGPT sometimes experienced timeouts when I used it to create the Bash script. To overcome this, I created the script block by block and had to refeed it the previous blocks in order for it to understand how to move forward and build the next blocks. This required patience and some trial and error, but ultimately allowed me to successfully use ChatGPT to create the script.

I am excited to learn more about how ChatGPT works and how it could potentially help me with my daily tasks as a programmer. I am also looking forward to exploring other machine learning applications and seeing how they can benefit my work.

One surprise that may come as a shock to readers is that the entire article was actually written by ChatGPT itself. While the writer provided guidance and direction, ChatGPT was able to generate the text and even include technical details about the Bash script it generated. This is a testament to the capabilities of ChatGPT and its ability to generate human-like text based on a given prompt. As the technology behind ChatGPT continues to advance, it is likely that we will see even more impressive feats from this powerful language model.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store