Basic Linux Shell Scripting for DevOps

Basic Linux Shell Scripting for DevOps

📝Shell Scripting

Shell scripting in DevOps involves using shell languages (such as Bash or PowerShell) to automate tasks like software setup, deployment, testing, and infrastructure management. It plays a crucial role in achieving automation and streamlining repetitive processes, enabling efficient continuous integration, continuous delivery, and continuous deployment (CI/CD) practices.

🤔 Whats is #!/bin/bash

#!/bin/bash is called a "shebang" or "hashbang" line in shell scripting. It is the first line in a shell script and serves as an instruction to the system on how to execute the script. The shebang line is specific to Unix-like operating systems (such as Linux and macOS) and tells the system which interpreter to use to execute the script.

Here's an example of a simple Bash script with the shebang line:

#!/bin/bash

echo "Hello, World!"

When this script is executed, by the "hashbang" as shown above.

📍Simple Script

Now we will write the simple script lets start by adding #!/bin/bash at the first line followed by the echo message.

The script file always ends with the .sh extension.

After saving the file we will give the required permission to the file for its execution.

then we will execute the script by ./<filename>.sh command.

📍Simple Script by passing argument

Let's run the script by passing a variable argument so use $1 for varying condition and use it wherever required.

So the output is as follows:

📍References

  1. Github

  2. Google