Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, I am pretty new to the shell scripting. Today I am stuck with the usage of positional variables. I want a shell script which takes input from command ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    3

    Positional variable $#

    Hi All,
    I am pretty new to the shell scripting. Today I am stuck with the usage of positional variables. I want a shell script which takes input from command prompt, but from the third positional variable onwards what ever i enter should be taken as a single string. for eg: I am entering username password emaild id and then some numbers 234 456 789 ie

    #username password emaild id 234 456 789

    what ever i entered as numbers should be taken as strings. for this i wrote a script and itz not working fine. Kindly help me to sort this out....

    dep="$(4)"

    num=$#;

    i=5;

    while($i -le $num)

    do
    dep=dep$i;
    i=$($i+1);
    done


    hope my logic is correct. but the output is weird.

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    There are various ways to do this. First of all, you could require the arguments to be entered properly, e.g.

    Code:
    myscript "234 456 789"
    instead of

    Code:
    myscript 234 456 789
    If that is not acceptable, you can assign the positional parameters to your variables, then shift the parameters and assign the rest to another variable, i.e.

    Code:
    var1="$1"
    var2="$2"
    shift 2
    rest="$@"

  3. #3
    Just Joined!
    Join Date
    Dec 2008
    Posts
    3
    Thank you and itz working fine now...

Posting Permissions

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