There's no mystery that the number increases. $$ expands to the PID of the current shell, and each time you run the script it's run into a new shell. So, it's simple maths.
I have no idea about what you are trying to do. Maybe if you explain that we can help you. If what you wanted is to access a file that's called literally 'scd.$$', then use single quotes around it so the $$ is not expanded.
EDITED:
Quote:
Originally Posted by bencharluo
you mean when I exec sh test.sh.
The kenel hand out a process ID to the program?
|
When you run a shell script, it doesn't matter if you use "sh script.sh" or "./script.sh" to run it, a new shell is spawned. The script is not run in your current shell, but into a new session with it's own local environment. The new shell is a new process, with a new unique PID. The pid of this new shell is what $$ will return. For more info read the bash man page.