# Shell Scripting Made Easy

### Explain in your own words and examples, what is Shell Scripting for DevOps.

Shell is a command-line interface that allows users to interact with the operating systems by entering commands. Shell Scripting is an open-source computer program designed to be run by the Unix/Linux shell. In Shell Scripting, we have to write a series of commands to execute the program. /

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

bash stands for Bourne again shell.

to know which bash was used in a shell the command is -

```plaintext
dell@dell-Inspiron-3576:~/Desktop$ which bash
/usr/bin/bash
```

here the output is- /usr/bin/bash.

#!/bin/bash is an instruction that was given to the computer that I am ready to write a shell script. Inside this #!/bin/bash instruction, different commands were written.

In #!/bin/sh it specifies that the script should be executed and interpreted using the sh shell, which is a bourne shell or a compatible shell.

### Write a Shell Script which prints I will complete #90DaysOofDevOps challenge.

first, create a file i.e nano first\_shell.sh.Here Nano is a text editor in Linux os. Then write the below code-

```plaintext
#!/bin/bash

echo "I will complete 90DaysOofDevOps challenge"
```

to run the file write- bash first\_shell.sh.output is-

```plaintext
 dell@dell-Inspiron-3576:~/Desktop/scripts$ nano first_shell.sh
 dell@dell-Inspiron-3576:~/Desktop/scripts$ bash first_shell.sh
 I will complete 90DaysOofDevOps challenge
```

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

```plaintext
#!/bin/bash

echo "hi guys"

#echo $BASH
 
name="Achyut"

echo "hello ${name}, please enter phone no"

read phone no

echo "my phone no is"

echo "friend: hi $1"

sleep 2

echo "me: hi bro,how are you"

sleep 2

echo "friend: Iam fine bro"
```

output is-

```plaintext
dell@dell-Inspiron-3576:~/Desktop/scripts$ nano second_shell.sh
dell@dell-Inspiron-3576:~/Desktop/scripts$ ./second_shell.sh abhishek
hi guys
hello Achyut, please enter phone no
8834523451
my phone no is
friend: hi abhishek
me: hi bro,how are you
friend: Iam fine bro
```

### /Wite an Example of If else in Shell Scripting by comparing 2 numbers.

```plaintext
#!/bin/bash
echo "enter a number"
read number
if [ $number -gt 10 ]
then
echo "number is greater than 10"
else
echo "number is less than 10"
fi
```

output is-

```plaintext
enter a number
7
number is less than 10
```
