Creating a Simple Bash Script

Devin Moreland
All Things DevOps
Published in
2 min readJul 11, 2022

Simple way to Bash script

Fount this article in my drafts from when I was learning Linux and decided to post it.

Purpose

To create a simple article showing how to create a Bash script in vim as a future reference for me or any others than may need it.

We will assume our server is done up and running.

Step 1: To create a Bash script we need to create a file and open it using vim

vim File.sh

The .sh shows us that it is a script.

Step 2: Always start out our bash script with a shebang #!/bin/bash, this tells our system to use Bash as the default shell. After this we will enter our script. Lets enter a sample script that will greet you.

#!/bin/bash
echo “Please enter your name”
read name
echo “Hello name”

Lets explain what is happening here. The first echo command is what will be displayed on the screen. The read command will listen for what we enter on screen, and create the variable name. Lastly the echo command will say Hello name.

One last thing before we run our script, we need to change the permission to give us execute permissions so we can run the script.

chmod 744 File.sh

To run the script enter

./File.sh

Then enter your name. I will post a picture showing what it should look like.

--

--