Skip to main content

Day 04 — Basic Linux Shell Scripting







  1. Explain in your own words and examples, what is Shell Scripting for DevOps.
  2. What is #!/bin/bash? can we write #!/bin/sh as well?
  3. Write a Shell Script which prints I will complete #90DaysOofDevOps challenge
  4. Write a Shell Script to take user input, input from arguments and print the variables.
  5. Write an Example of If else in Shell Scripting by comparing 2 numbers
  6. Was it difficult?



1. What is Kernel
The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.

2. What is Shell
A shell is special user program which provide an interface to user to use operating system services. Shell accept human readable commands from user and convert them into something which kernel can understand. It is a command language interpreter that execute commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.

3. 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.

4. Explain in your own words and examples, what is Shell Scripting for DevOps.
Shell scripting is a way to automate tasks in a Unix-based operating system, such as Linux or macOS. It involves writing a series of commands in a script file, which can then be executed all at once, rather than running each command separately.

5. What is #!/bin/bash? can we write #!/bin/sh as well?
The line “#!/bin/bash” is called a shebang, and it specifies the path to the interpreter for the script. In this case, the script will be interpreted by the bash shell. Yes, you can also use “#!/bin/sh” to specify the “sh” shell as the interpreter.

6. Write a Shell Script which prints “I will complete #90Days0ofDevOps challenge”
This script has a single line of code, which uses the “echo” command to print a message to the terminal. The message is 
enclosed in quotation marks, so it is treated as a single string by the shell.




#!/bin/bash

echo "I will complete #90DaysOofDevOps challenge"



7. Write a Shell Script to take user input, input from arguments and print the variables.
The script begins by displaying a message asking the user to enter their name, and then uses the “read” command to get the user’s input and store it in the “name” variable. Then, the script gets the first argument passed to it (in this case, “Manager” ) and stores it in the “position” variable. Finally, the script prints both variables using the “echo” command.

#!/bin/bash

# Get the user's name as input
echo "Enter your name: "
read name

# Get the first argument passed to the script
position=$1

# Print the variables
echo "Name: $name"
echo "Position: $position"


8. Write an Example of If else in Shell Scripting by comparing 2 numbers
When the script is run, it gets the two numbers to compare as arguments and stores them in the variables “num1" and “num2". Then, it uses an “if” statement to compare the values of these variables. If “num1” is greater than “num2”, the first block of code is executed and the message “10 is greater than 5” is printed to the terminal. If “num1” is not greater than “num2”, the second block of code is executed and the message “5 is less than or equal to 10” is printed to the terminal.

#!/bin/bash

# Get the two numbers to compare as arguments
num1=$1
num2=$2

# Compare the numbers
if [ $num1 -gt $num2 ]
then
  echo "$num1 is greater than $num2"
else
  echo "$num1 is less than or equal to $num2"
fi

Comments

Popular posts from this blog

NGINX Web App Deployment for DevOps

  Step 1: Create AWS instance. Step 2: Install NGINX Step 3: Install docker and create a Container for note-app. Step 4: Set up a reverse proxy. Step 5: Copy the code to the root folder. Step 6: Connect the database nginx specification Step 1: Create AWS instance. Log in to the AWS account and create an ec2 server. Nginx is a web server that will serve you static web files. So we require a server. - Create an EC2 instance and name it 'nginx-project-demo'. Also, don't forget to allow HTTP and HTTPS traffic. ( For sake of practice, let's select an Ubuntu machine with t2.micro instance type) Update your server using the command.   sudo apt-get update Step 2: Install NGINX Now install Nginx using the command below. sudo apt install nginx Check the status of nginx. systemctl status nginx Restart the nginx server with root user permission. sudo systemctl restart nginx To check further nginx is successfully installed on your server is to use the server IP and paste it into the...

Linux fundamental day 2 train with shubham

 Linux Founder—Linus Torvalds Linus Benedict Torvalds is a Finnish software engineer best known for having initiated the development of the Linux kernel and git revision control system. History of LINUX Linux came from a Unix family, Linux is free and open-source software operating systems, which was developed by Linus Torvalds in September 1991. In 1991, When Linus Torvalds was a student at the University of Helsinki, Finland, USA. He developed the first code of Linux 0.01 and post it on Minix newsgroup 17 Sep 1991, his code become so popular people encourage him to develop new code and he was lead to develop new code and release the first “official” version of Linux, version 0.02 on October 5, 1991. Today many year pass and Linux become one of the most popular operating system. Today 90% fastest Supercomputers out of 500 run on Linux variant including top 10. Linux File System Hierarchy + In Linux everything is represented as a file including a hardware program, the files are s...