Tuesday, September 4, 2012

Interview Questions for Linux Administrator

Learning shell scripting is very easy but we need to start it from basic of shell scripting tutorial. I am writing this article because of many of us confused about these two operators.

There are many ways to pass argument to unix shell script as follows:
Pass command line argument:
1.       In this you don't need to give arguments in double quotes. You can use this argument in script as $1,$2,and $3. Assigned value becomes $1=10, $2=20,$3=30.
$ sh test.sh 10 20 30       
2.       If argument contains space or wild card character then need to put it in double quotes.  You will get these arguments in script as $1="first Argument" and $2="Second Argument".
$sh test.sh "first Argument" "Second Argument"                                             

Shift Operator in Solaris/Linux:
3.       If there are more than 10 arguments and you want to pass from command line then you need to use shift operator.
$sh test.sh 10 20 30 40 50 60 70 80 90 100 110 120 130
$vi test.sh
#!/bin/bash
echo $1                                                //10
echo $2                                                //20
echo $7                                                //70
echo $9                                                //90
shift;
echo $9                                                //100
shift 2;
echo $8                                                //110
echo $9                                                //120
Instead of shift operator you can use echo ${10} or echo {11} like this. In this way, you can go ahead with more arguments.

Know more about :  Linux Shell scripting tutorial
4.       If you are giving command line input to script then you can use $* or $@ to display all argument as comma separated and considering a single string. For example:
$sh test.sh 10 20 30 40 50 60 70 80 90 100 110 120 130
$vi test.sh
#!/bin/bash
echo $*                                                //10
and  output is as
10 20 30 40 50 60 70 80 90 100 110 120 130

download shell scripting pdf


Advanced use of sed command in Linux      
Posted by Machindra Dharmadhikari On 9/04/2012 05:44:00 PM 1 comment

1 comment:

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner