To understand the bash scripting… One must be aware of the Top 100 Linux commands with hands on practice. You can study this from Youtube, Google surf.
Bash Scripting
Open your Linux Shell or Terminal
-
To find what type of shell you are using type
shiva@hypo-cloudeva:~$ echo $PATH
/home/shiva/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
-
What is Shebang ?
!/bin/bash this is known as Shebang and whenever you write a script it must start with Shebang.
Let’s see an example of executing a script
shiva@hypo-cloudeva:~$ mkdir scriptapril24-2022 -- creating a directory or folder
shiva@hypo-cloudeva:~$ cd scriptapril24-2022/ -- navigating inside the directory or folder
shiva@hypo-cloudeva:~/scriptapril24-2022$ nano basicshellscript.sh -- creating a file using nano editor
shiva@hypo-cloudeva:~/scriptapril24-2022$ chmod 744 basicshellscript.sh -- giving executable permission to the file
inside the file we are typing an echo command.. echo command repeats whatever you typed inside the echo
example –
shiva@hypo-cloudeva:~/scriptapril24-2022$ nano basicshellscript.sh
You will type the below inside the nano editor
!/bin/bash
echo "hello world"
shiva@hypo-cloudeva:~/scriptapril24-2022$ ./basicshellscript.sh -- we are running the script here
hello world --- the script gets executed and returns the output (echo command)
shiva@hypo-cloudeva:~/scriptapril24-2022$
bash basicshellscript.sh -- this is another way of executing script
hello world --- output of echo command inside the script
Lets see how a script can ask user to input data
shiva@hypo-cloudeva:~/scriptapril24-2022$
nano basicshellscript.sh
inside the nano editor type the below
!/bin/bash
echo "hello world"
echo "what is your name"
read name --- this read command in nano editor of script asks for input
echo "how are you dong today"
read answer -- this read command in nano editor of script asks for input
echo "Is scripting is fun"
read reply -- this read command in nano editor of script asks for input
echo "have a good one"
PFB ..
Output – PFB
shiva@hypo-cloudeva:~/scriptapril24-2022$
bash basicshellscript.sh
hello world
what is your name
Aravind-Shiva
how are you dong today
very well
Is scripting is fun
definitely
have a good one
-- article to be continued
(The word document I created earlier is replicated here)
Top comments (0)