mirror of https://github.com/tLDP/LDP
20 lines
449 B
Bash
20 lines
449 B
Bash
#!/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
|