Understanding Shell Scripting with Basic

Mihir SuratwalaMihir Suratwala
2 min read

Last Blog Review

In the last blog we understood,the logic of writing the cronjob commands.

A. What is script ?

\=> Script in which there are sequence of commands for a UNIX-based operating system. Also, they are written in Shell which is a black screen you see. Extension of shell script file is ".sh". The type of shell which we are using is bash. To know which type of shell we are using "echo $shell".

B. What is “#!“ ?

\=> While writing any shell scripting we need to start with "#!" which is called as sharp-exclamation, sha-bang, hashbang, pound-bang, or hash-pling. Then we need to check which type of shell we are having in the Linux OS. using command "echo $SHELL". In this Linux OS we have GNU based Bourne-Again Shell denoted by "bash". So, along with "#!" we will write the type of shell we have i.e bash & bash is in bin directory so "#!/bin/bash"

C. “echo” to print the output ?

\=> In shell scripting to print anything we use "echo" command, for ex. echo "hi"

D. What is variable ?

\=> Variables are who vary. Variables and Constants are differentiated as "Variables start with $ sign". While assigning a value to a variable $ sign is not req. Only when variables are used then use $ sign. Variables in Shell scripting are case sensitive and are alphanumeric and underscores i.e. only alphabets, numbers, underscores are allowed.

Now if we want to use inbuilt variable to be written in "echo" statement then we can write in this format $(inbuilt_variable_name).

for ex. date is a inbuilt command and we want to use it in echo command to display date, then write : echo "Today is $(date)"

If we want to use an user-defined variable to be written in "echo" statement, then we write in this format $user-defined-variable-name.

for ex. this is a user-defined-variable and it has my name, name = Mihir and we want to print it then write : echo "$name".

E. Commenting in shell script ?

\=> To give single line comment in shell script use "#"

Conclusion →

In this blog we understood, the simple shell scripting basic’s which are highly necessary when we start writing the shell scripts. Understanding what is script, what is #!, how to declare variables, how to add comments.

Image credit - https://images.app.goo.gl/VzbyfNHaB1c1LwCh6

💡
That’s a wrap for today’s post! I hope this has given you some valuable insights. Be sure to explore more articles on our blog for further tips and advice. See you in the next post!
0
Subscribe to my newsletter

Read articles from Mihir Suratwala directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mihir Suratwala
Mihir Suratwala

Hi, How are you !! Hope you doing good.... I got introduced to Cloud initially. As I went ahead learning what is cloud and how it works, then got to know a field which is DevOps that makes Cloud model more effective. So, as I started working & got good experience on AWS. I have been learning the DevOps tool and technologies on how to use it with the Cloud, which will give me good understanding on how Cloud and DevOps go hand in hand to deploy my applications.