Visit Our UNIX and Linux User Community


What is $! ?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What is $! ?
# 1  
Old 11-04-2009
MySQL What is $! ?

Hi All,

What is the meaning for $! in shell? I am trying to understand a script. And it has the following sequence of commands.

Code:
local@usr> a=1
local@usr> echo $a
1
local@usr> echo $!a
a

It is printing the variable back. Is it all for that? What are the other $x option you have? Few I know are $$, $*, $?. If anyone can point me to a good source, it will be helpful.
# 2  
Old 11-04-2009
$! is a special shell variable which gives the process ID of the last background job you ran.

What does this give you:
Code:

local@usr> a=1
local@usr> echo $a
1
local@usr> sleep 1 &
local@usr> echo $!a


# 3  
Old 02-25-2010
Dear Friend,

In shell $! is used to print the last execution process id of the background process.

Code:
    
 sleep 100 & 
 [1] 29950
echo $!
29950



In perl if you use $!, it is represent the last system error.

If any errors are occur, that will be stored in the variable $!.

Last edited by murugaperumal; 02-25-2010 at 09:38 AM..
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #475
Difficulty: Medium
A Yottabyte (YB) equals 1,208,925,819,614,629,174,706,176 bytes.
True or False?

Featured Tech Videos