Day 4 DevOps challenge

Day 4 DevOps challenge

Basic Linux shell scripting for DevOps

✔️What is Linux shell scripting?

Linux shell scripting is a method of automating tasks using commands in a script file. It utilizes a shell interpreter, often Bash, to execute the script. Scripts can include variables, loops, conditionals, and other control structures to perform various operations on the command line. Shell scripting is widely used for system administration, automation, and customization in Linux environments and make your life easier by saving you time and effort.

✔️What is shell scripting in DevOps?

In DevOps, shell scripting plays a crucial role in automating tasks and workflows. It enables the integration and orchestration of various tools and processes in the software development lifecycle. Shell scripts help streamline deployments, configuration management, and system administration, facilitating efficient and consistent operations within a DevOps environment.

✔️What is #!/bin/bash ?

#!/bin/bash is the first line of a shell script that Specifies that the script should be executed using the Bash shell interpreter. Bash is a popular and feature-rich shell that provides advanced functionalities for scripting and interacting with the Linux/Unix command line. It includes additional features beyond the POSIX standard.

✔️What is #!/bin/sh

#!/bin/sh Specifies that the script should be executed using the default system shell, which is often a symlink to another shell such as Bash or Dash. However, "#!/bin/sh" specifically indicates that the script should run using the standard POSIX shell. POSIX shells aim for greater compatibility across different Unix-like systems and adhere to a standardized set of features defined by the POSIX standard.

✔️What is #!/bin/bash? can we write #!/bin/sh as well?

The shebang #!/bin/bash is the first line of a shell script that specifies the interpreter to be used, in this case, Bash. Bash is a widely used shell with additional features compared to #!/bin/sh which is typically a symlink to another shell, like Bash or Dash. However, you can use #!/bin/sh if your script only uses features available in the POSIX standard, making it more portable across different Unix-like systems.

In summary, using #!/bin/bash allows you to take advantage of Bash's extended features, while #!/bin/sh ensures more portability by sticking to the POSIX standard and relying on the default system shell.

✔️Shell script to print any text :

echo "I will complete #90DaysOofDevOps challenge"

✔️Shell Script to take user input, input from arguments and print the variables:

#!/bin/bash

# Taking user input
echo "Enter your name:"
read name

# Taking input from command-line argument
age=$1

# Printing the variables
echo "Name: $name"
echo "Age: $age"

✔️Example of If else in Shell Scripting by comparing 2 numbers:

#!/bin/bash
echo "Enter any 2 values"
read a b
if [[ $a > $b ]]
then
echo "$a is greater"
else
echo "$b is greater"
fi

Thank you so much for reading

Please let me know if you suggest some edit and improvements for this blog.

Follow me at LinkedIn to see interesting posts like this : )

https://www.linkedin.com/in/prabir-kumar-mahatha-6a0025248/