what does echo $$, $? $# mean


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting what does echo $$, $? $# mean
# 1  
Old 07-30-2008
what does echo $$, $? $# mean

Hi I am not good in scripting, can anyone of you please help me, with these echo $$, $? $# mean, any good guide / doc on these basics would be much more helpfull.

Thanks in advance.
# 2  
Old 07-30-2008
The manual page for your shell documents these.

$$ is the PID of the current process.

$? is the return code of the last executed command.

$# is the number of arguments in $*

$* is the list of arguments passed to the current process
This User Gave Thanks to era For This Post:
# 3  
Old 07-30-2008
MySQL

Hi gokulagiridaran,
There are many other that would help you scriptiong, here are few that would really help you.

$_- The default parameter for a lot of functions.
$.- Holds the current record or line number of the file handle that was last read. It is read-only and will be reset to 0 when the file handle is closed.
$/- Holds the input record separator. The record separator is usually the newline character. However, if $/ is set to an empty string, two or more newlines in the input file will be treated as one.
$,- The output separator for the print() function. Nor-mally, this variable is an empty string. However, setting $, to a newline might be useful if you need to print each element in the parameter list on a separate line.
$\-- Added as an invisible last element to the parameters passed to the print() function. Normally, an empty string, but if you want to add a newline or some other suffix to everything that is printed, you can assign the suffix to $.
$#-- The default format for printed numbers. Normally, it's set to %.20g, but you can use the format specifiers covered in the section "Example: Printing Revisited" in Chapter 9to specify your own default format.
$%-- Holds the current page number for the default file handle. If you use select() to change the default file handle, $% will change to reflect the page number of the newly selected file handle.
$=-- Holds the current page length for the default file handle. Changing the default file handle will change $= to reflect the page length of the new file handle.
$- -- Holds the number of lines left to print for the default file handle. Changing the default file handle will change $- to reflect the number of lines left to print for the new file handle.
$~-- Holds the name of the default line format for the default file handle. Normally, it is equal to the file handle's name.
$^-- Holds the name of the default heading format for the default file handle. Normally, it is equal to the file handle's name with _TOP appended to it.
$|-- If nonzero, will flush the output buffer after every write() or print() function. Normally, it is set to 0.
$$-- This UNIX-based variable holds the process number of the process running the Perl interpreter.
$?-- Holds the status of the last pipe close, back-quote string, or system() function.
$&-- Holds the string that was matched by the last successful pattern match.
$`- Holds the string that preceded whatever was matched by the last successful pattern match.
$'-- Holds the string that followed whatever was matched by the last successful pattern match.
$+-- Holds the string matched by the last bracket in the last successful pattern match. For example, the statement /Fieldname: (.*)|Fldname: (.*)/ && ($fName = $+); will find the name of a field even if you don't know which of the two possible spellings will be used.
$*-- Changes the interpretation of the ^ and $ pattern anchors. Setting $* to 1 is the same as using the /m option with the regular expression matching and substitution operators. Normally, $* is equal to 0.
$0-- Holds the name of the file containing the Perl script being executed.
$<number>-- This group of variables ($1, $2, $3, and so on) holds the regular expression pattern memory. Each set of parentheses in a pattern stores the string that match the components surrounded by the parentheses into one of the $<number> variables.
$[-- Holds the base array index. Normally, it's set to 0. Most Perl authors recommend against changing it without a very good reason.
$]-- Holds a string that identifies which version of Perl you are using. When used in a numeric context, it will be equal to the version number plus the patch level divided by 1000.
$"-- This is the separator used between list elements when an array variable is interpolated into a double-quoted string. Normally, its value is a space character.
$;-- Holds the subscript separator for multidimensional array emulation. Its use is beyond the scope of this book.
$!-- When used in a numeric context, holds the current value of errno. If used in a string context, will hold the error string associated with errno.
$@-- Holds the syntax error message, if any, from the last eval() function call.
$<- This UNIX-based variable holds the read uid of the current process.
$>-- This UNIX-based variable holds the effective uid of the current process.
$)-- This UNIX-based variable holds the read gid of the current process. If the process belongs to multiple groups, then $) will hold a string consisting of the group names separated by spaces.
$:-- Holds a string that consists of the characters that can be used to end a word when word-wrapping is performed by the ^ report formatting character. Normally, the string consists of the space, newline, and dash characters.
$^D-- Holds the current value of the debugging flags. For more information.
$^F-- Holds the value of the maximum system file description. Normally, it's set to 2. The use of this variable is beyond the scope of this book.
$^I-- Holds the file extension used to create a backup file for the in-place editing specified by the -i command line option. For example, it could be equal to ".bak."
$^L-- Holds the string used to eject a page for report printing.
$^P- This variable is an internal flag that the debugger clears so it will not debug itself.
$^T-- Holds the time, in seconds, at which the script begins running.
$^W-- Holds the current value of the -w command line option.
$^X-- Holds the full pathname of the Perl interpreter being used to run the current script.
These 3 Users Gave Thanks to yesmani For This Post:
# 4  
Old 07-30-2008
Thanks a lot.!
# 5  
Old 07-30-2008
Note that yesmani's response is the documentation for these variables in Perl. I was assuming you meant the shell. (In particular, I don't think $# alone makes any sense in modern Perl. Looks like the table above was for Perl 4, maybe.)
# 6  
Old 07-30-2008
Hi era,
thank you, if you have those variables which applies for BASH can you pls fwd me ?

Thank you .
Gokul.
# 7  
Old 07-30-2008
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between echo `ls -l` and echo "`ls -l`" ?

Hi guys, Been messing around with shell programming for a couple of days and I found something that was pretty odd in the behavior of the echo command. Below is an example-: When I type the following in my /home directory from my lxterminal in Debian-: echo "`ls -l`" I get the... (2 Replies)
Discussion started by: sreyan32
2 Replies

2. UNIX for Dummies Questions & Answers

echo

Hello, I'm working with ksh. I was working with the echo command That is echo "Today is $date" which would show for example Toady is 7/12/12 which was fine however, know I only recieve the first part of the echo without the date. Today is Could I have edited the echo... (9 Replies)
Discussion started by: JD_Sal
9 Replies

3. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

4. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

5. Shell Programming and Scripting

Help with echo

Hi Guys, I need to print a value in the same line , But when we use the echo instead the loops (while), the value goes to the next line.. Can you help me in this.. Thanks For your help in advance. (6 Replies)
Discussion started by: mac4rfree
6 Replies

6. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

7. Shell Programming and Scripting

echo !.

can someone tell me what does this code do? echo !. (2 Replies)
Discussion started by: ryandegreat25
2 Replies

8. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

9. UNIX for Dummies Questions & Answers

echo

Is there a way to get echo to make newlines without using any type of quotes? I've done a lot of searches and went into my Linux book to no avail. I'm trying to write five separate lines to a file. I can get echo to accept all five lines like this echo \ \this is line 1\ \this is line 2\ >... (6 Replies)
Discussion started by: Trekker182
6 Replies

10. Shell Programming and Scripting

echo

what is the meaning of this echo $description | wc -m` -ne "1" (0 Replies)
Discussion started by: debasis.mishra
0 Replies
Login or Register to Ask a Question