Find the answer to your Linux question:
Results 1 to 2 of 2
Im taking a class on Unix/Linux and now we have reached a point in the class where I have no experience: Scripting. Im trying to make a bash script for ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    1

    Bash script print positional parameters

    Im taking a class on Unix/Linux and now we have reached a point in the class where I have no experience: Scripting.
    Im trying to make a bash script for a homework excercise. I need to make a script that prints out 10 positional parameters. After some research I found out that by default there are 10, but 0 is actually the name of the script so I believe that wont count for this excercise.
    I looked a little more and found the shift command.

    This is what I have so far:
    #!/bin/bash

    echo $1
    echo $2
    echo $3
    echo $4
    echo $5
    echo $6
    echo $7
    echo $8
    echo $9
    shift 1
    echo $9

    This gets the job done, but is this the correct/easiest way to do what Im trying to do? I would like to get them all on one line but with the shift command in there I havent been able to so far.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Use a for loop with the seq command and shift the parameters after every "echo $1".

    Have a read of these guides:

    http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
    http://www.tldp.org/LDP/abs/html/index.html

    and check the manpage of seq.

    Regards

Posting Permissions

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