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...
- 01-17-2008 #1Just 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
- 01-17-2008 #2
$# 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.
Execute it like thisCode:#!/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
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
- 01-17-2008 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 10
Thanks...
now i got the point.
thanks again.
Yogender
- 01-20-2008 #4
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
- 01-20-2008 #5Linux Engineer
- 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, drlWelcome - 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 )


Reply With Quote