I m gonna discuss about shell scripting in Linux. It’s very useful in your administrative work as it minimizes your work and save time, also does repeated things (which you may have encountered in daily tasks) . And you can even make your own simple programs and utilities as per you requirement.
A shell script is a set of commands which is written for ‘shell’ (command line interpreter) of an operating system to perform an specific task.
In Linux there are various types of shells - sh, bash ,ksh, csh , tcsh, fish etc .
To start scripting, you first need to have knowledge of some basic terms such as grep, awk, sed, cut etc.
Let's have an example of a simple bash shell script which includes printing a message and command line input for variables
and printing those values-
#!/bin/bash
echo "Please Enter two numeric values"
read n1 n2
echo " The value you have entered are $n1 and $n2"
Here the first line is header which indicates path to script engine, in our case it is /bin/bash. It means bash shell will be used.
Next we have used 'echo'. It is used to display the message written inside quotes. In third line there is 'read' which is to take input values through command line for the variables (in our case n1 and n2).
And as you have probably guessed we are printing the message and the values for those variables in fourth line ,which we do by using '$' sign.
So, to run that script , just write above lines in a text file,save it (let say test.sh) give execute permission to that file n u are ready to go...
# chmod +x test.sh
# ./test.sh
No comments:
Post a Comment