Introduction:
In the world of DevOps, having a solid understanding of Linux shell scripting is essential. Shell scripting allows DevOps engineers to automate tasks, streamline workflows, and unleash the full potential of their Linux environments. ๐
What is shell?
The shell provides a command-line prompt where users can type commands to perform various tasks such as running programs, managing files and directories, configuring system settings, and more. It interprets the commands entered by the user and communicates with the operating system to execute those commands.
What is Linux shell scripting?
A shell script is a computer program designed to be run by a linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.
What is
#!/bin/bash?
can we write#!/bin/sh
as well?#!/bin/bash A shebang line used in script files to set bash, present in the '/bin' directory, as the default shell for executing commands present in the file. It defines an absolute path /bin/bash to the Bash shell.
Yes, you can use #!/bin/sh as the shebang line in your shell script. The shebang line (#!/bin/sh) indicates the interpreter to be used to execute the script. In this case, it specifies that the script should be interpreted by the /bin/sh shell. While #!/bin/bash explicitly specifies the Bash shell as the interpreter, #!/bin/sh is more generic and typically points to the default shell interpreter on most Unix-like systems.
Tasks:
Write a Shell Script which prints I will complete #90DaysOofDevOps challenge.
Step 1: Create a file with .sh extention ex. devops_challenge.sh and write #!bin/bash in it.
Step 2: Then, make the file executable using the following command:
chmod +x devops_challenge.sh
Step 3: Finally, run the script by executing:
./devops_challenge.sh
Step 4: You should see the following output:
Write a Shell Script to take user input, input from arguments and print the variables.
Step 1: Create a file named test_name.sh and write the following shell script in it.
Step 2: Then, Make it executable using the command : chmod +x test_name.sh
Step 3: Finally, run the script by executing: ./test_name.sh
Step 4: You will see the following output. Enter your name and it will get print.
Write an Example of If else in Shell Scripting by comparing 2 numbers.
There are several different shells available in Linux, with Bash (Bourne Again SHell) being the most commonly used. Other popular shells include Zsh (Z Shell), Ksh (Korn Shell), and Csh (C Shell). Each shell has its own set of features, syntax, and capabilities, although they generally provide similar functionality.
Conclusion:
Mastering Linux shell scripting is a crucial skill for DevOps engineers. With the power of shell scripting and the ability to automate tasks, DevOps professionals can enhance their productivity and streamline their workflows. So, embrace the command-line interface, explore the vast world of shell scripting, and unlock the true potential of Linux for your DevOps journey! ๐ช๐ฅ