Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, Could any one please suggest me what does echo $# and echo $$ prints. I know that echo $? gives us the exit status. Thanks in advance. Regards, Yogender...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Posts
    10

    What is echo $#

    Hi,

    Could any one please suggest me what does echo $# and echo $$ prints.

    I know that echo $? gives us the exit status.

    Thanks in advance.

    Regards,
    Yogender

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    $# prints list of parameters passed to script and $$ prints process id.
    If execute echo $$ at command prompt, it will print process id of shell only.
    Code:
    #!/bin/bash
    
    # Its a test script : test.sh
    
    echo "First Parameter : \$1 = $1"
    echo "Second parameter : \$2 = $2"
    echo "Total passed parameters : \$# = $#"
    echo "All parameters : \$* = $*"
    echo "Process Id  : \$$ = $$" 
    exit 0
    Execute it like this
    Code:
    ./test.sh 1 2 3 4 5
    Code:
    echo $$
    ps
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined!
    Join Date
    Nov 2007
    Posts
    10
    Thanks...

    now i got the point.

    thanks again.

    Yogender

  4. #4
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    You may be aware of this, but if i'm not mistaken, $? gives you the return value of the last command / function, which can include an exit statement, but it does for ALL functions and commands. This doesn't seem like a huge deal, but i wasted a couple hours writing a script that absolutely would not work how i designed it because i didn't realize that almost every action updates the $? variable.
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  5. #5
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    The table, Special Shell Variables, at http://www.tldp.org/LDP/abs/html/refcards.html#AEN19999 , is part of a tutorial, both of which may be useful ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

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