Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
Write a shell script named displayargs that prints FOUR lines. The first line tells the name that was used to invoke the script, the second line tells how many parameters ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    6

    [SOLVED] any one can write this script please

    Write a shell script named displayargs that prints FOUR lines. The first line tells the name that was used to invoke the script, the second line tells how many parameters there were, the third line tells what the last parameter was, and the fourth line tells what the first parameter was.

    For example:

    $ displayargs a b c

    My name is displayargs.

    There were 3 parameters.

    The last one was c.

    The first one was a.

    $

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    Hi and welcome.
    Sorry, but forum rules forbid homework questions
    http://www.linuxforums.org/forum/lin...ums-rules.html

    But the task is not that hard.
    Read here and you will surely master it
    Advanced Bash-Scripting HOWTO
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    6
    its not an asiment its an excersice from a book i cant handle it anyway thanks

  4. #4
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    ok, so then the exercise book will give you the informations before actually asking questions about them.

    One more hint, bash has special variables
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Feb 2010
    Posts
    6
    i wrote it as below and i got the same output is that correct??

    #!/bin/bash
    clear
    echo "My name is displayargs"
    echo "There were 3 parameters"
    echo "The last is c"
    echo "The first is a"

  6. #6
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    It´s a start, but doesnt cover the scope of the task.

    If you would issue

    $ displayargs a b c d

    Then the output should look like this

    My name is displayargs.
    There were 4 parameters.
    The last one was d.
    The first one was a.


    ie: The script shall react to the number of arguments given to it, as well as its own name.

    Did you read the chapter about variables?
    Advanced Bash-Scripting HOWTO
    You must always face the curtain with a bow.

  7. #7
    Just Joined!
    Join Date
    Feb 2010
    Posts
    6
    i did but... i'm about to give up thank u bro..

  8. #8
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    ok, I will solve the first line (only)..

    try this in your script:
    echo $0
    You must always face the curtain with a bow.

  9. #9
    Just Joined!
    Join Date
    Feb 2010
    Posts
    6
    thank u bro,i have used it this way is it ok?

    echo "My name is $0"
    echo "There were $# parameters"
    echo "The last is ${!#}"
    echo "The first is $1"

  10. #10
    Just Joined!
    Join Date
    Feb 2010
    Posts
    6
    thank u so much bro now i got it i understood how varibles works in shell scripting thanks alot again brother

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...