📌Highlights: In this post we will learn about shell programming basic. This post cover so many basic commands which is useful in programming such as how we declare variable in shell program, display value of variable, how logical operator used in program, type of Relational operators, how we compare two strings, syntax of if statement with example, how for statement is used and their syntax.
⧭ Shell programming is basically a shell command which is interpreted by shell.
Let we first understand user memory variables:
$ a =800 (variable declaration)
$ echo a (It will display string / text which are written after echo command.)
here output is: a
$ echo $ a ( It will display value of a)
here output is: 800
Example:
$ ab = " ls -l "
$ b = " abc "
$ $ ab $ b (or) we can write ($ ls -l abc)
Let we understand program in shell:
# Program:
echo " I am very powerful $0 command "
echo " I have $# argument "
echo " My argument are : $* "
echo " My first argument is : $1 "
: wq
For running the above program write:
here the output will be:
Now remember:
$# For number of arguments
$* For name of arguments
$0 Command
$1 Command for first argument
$2 Command for second argument
$3 Command for third argument
and more ........
Note: ($1, $2, $3,....) are number of memory variables.
Statement of [For Statement]:
For variable in List .....
do
Command
Command
Command
-------
done
Example of For Statement:
$ vi xsort → Enter
clear
For x is $*
do echo " ......................."
echo " sorted content from file $x "
echo " ......................"
echo
sort $x
done
: wq
$
here the output is:
........................
Sorted content from file abc
---------------
---------------
---------------
Sorted content from file abc1
---------------
---------------
---------------
Sorted content from file abc2
---------------
---------------
---------------
No comments:
Post a Comment