What is Shell Script in Linux?
The beauty of the GNU/Linux operating system is that users can directly communicate with the shell via various commands. This is why a large number of software and servers run on Linux, thanks to the amazing concept of shell scripting, which enhances productivity and user interactivity directly with the shell.
The shell is a command-line interpreter that takes commands from the user and converts them into a form that the kernel can understand, it's also take input from keyboard, other input device and execute them according to that.
A shell script is a sequence of commands that specifies which activities need to be performed at a particular time and executes them at our convenience. It is used for repetitive tasks, monitoring system resources, and managing user accounts.
Now Let's understand some basic of Shell Scripting...
Very first thing which need to know is how to print something on shell and here the concept which is used called as echo..
Shell Script Printing
To print anything on terminal we can use and write sentence inside " " .
Let do this inside shell..
Here I am creating one file and then we will execute this..
To create shell script we need to give extension to the file as .sh
Open same file with vim editor to enter code inside it..
Let us understand some basic things
Here #! is know as shebang and with this kernel understand that this is shell script with bash as this execute in bash shell.
To run this file, two method one is simply put bash before the filename or use ./ before filename.
To run file with ./ we need change the mode of file as executable, here i give
executable mode to file by ch-mod.
Read input or variables from user..
First Method
Here i created one file as read_input.sh and enter the code inside it... here user input saved in variable as name and dob and same is use in printing with $variable_name.
to execute i change the mode of file and then use ./read_input.sh...
Second Method
Now here i will take input as an argument from user
while execute the same file i pass my argument before execute the file as shown below, here amit is an argument for my file which is name.
Once i hit enter to execute same file result shown as..
Kindly enter your name: amit
Thank you for the day, Toady we cover what is shell script with that how to print, read variables and read arguments from user by simple way...
What do you think? Share your perspective in the comments below!
Kindly follow and subscribe to the blogs...