unix help again (shell scripting)

Discussion in 'Mac Basics and Help' started by scan, Feb 15, 2006.

  1. scan macrumors 6502

    Joined:
    Oct 24, 2005
    #1
    When running a script whats a way to check whether arguments are being passed?
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    echo? e.g. echo $1.

    B
     
  3. scan thread starter macrumors 6502

    Joined:
    Oct 24, 2005
    #3

    i want to check if there was argument(s) passed
     
  4. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #4
    $# is the number of arguments passed.

    For example, if myscript contains the line
    Code:
    echo $#
    then you'd get this:
    Code:
    myscript
    0
    myscript all
    1
    myscript all your
    2
    myscript all your base
    3
    myscript all your base are
    4
    You can use a test like this:
    Code:
    [ $# -le 2 ] && exit 0
    to exit if there are fewer than two arguments.
     

Share This Page