[Ilugc] echo $$
- From: linux@xxxxxxxxxxxxxxxx (Suresh Ramasubramanian)
- Date: Thu Nov 11 22:18:40 2004
Sridhar R wrote:
sri@infinity:Applications$ echo $$
14654
What is this magic variable in bash?
Actually I did a 'mkdir $$' and to my surprise it created a directory
named '14654' !
It is a bash builtin that expands to the pid of a script / program's
instance.
http://www.tldp.org/LDP/abs/html/internal.html
#!/bin/bash
# self-exec.sh
echo
echo "This line appears ONCE in the script, yet it keeps echoing."
echo "The PID of this instance of the script is still $$."
# Demonstrates that a subshell is not forked off.
echo "==================== Hit Ctl-C to exit ===================="
sleep 1
exec $0 # Spawns another instance of this same script
#+ that replaces the previous one.
echo "This line will never echo!" # Why not?
exit 0
Other related posts: