When I use these shell commands:
[root@linux /tmp]# a=$$ [root@linux /tmp]# echo $a 3985
where does the value 3985 come from? And why?
$$ is the pid of the current process
host@controller:~$ echo $$ 12481 host@controller:~$ ps -p 12481 PID TTY TIME CMD 12481 pts/2 00:00:01 bash host@controller:~$
Since we execute
echo $? is the return code of the last executed command.
$# is the number of arguments
$* is the list of arguments passed to the current process
$[1 or 2 or ... n] value of each corresponding argument
That's why some people use it to construct a filename that's only used temporarily and then destroyed, as in this script fragment.
As mentioned above, the $$ in the filename will be the PID of the main script.