Shell Scripting|Linux

In this Article We will what is shell scripts and write few basic shell scripts.

What is a shell script?

A shell script is a list of commands in a computer program that is run by the Unix shell which is a command line interpreter. (Unix is a flavor of Linux)

A shell script is a line of instructions written in .sh file.

Let's write a simple Shell Script to create a file and write hello world in that script.

Open Shell Editor

vim shellscript.sh

#! /bin/bash

touch samplefile.txt

echo "this is the text in sample file">samplefile.txt

How to execute the script

bash shellscript.sh

#!/bin/bash is 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.

This is usually the default location of the Bash shell in almost all Unix-based operating systems.

#!/bin/sh is used where?

Executes the script using the Bourne shell or a compatible shell, with path /bin/sh

Let's write a simple shell script that prints "i will complete 90 days of devops challenge"

vim scipts.sh
#!bin/bash
echo "i will complete 90 days devops challenge"
:wq (press enter key)
bash scipts.sh

Write a Shell Script to take user input, input from arguments and print the variables.

Write an Example of If else in Shell Scripting by comparing 2 numbers