script does not close terminal after running

For a small script i want it so that the terminal closes when the script has completed its tasks.
To do so i use at the end if the script the following:

echo "Hello, World!" 
echo "Knowledge is power."
echo ""
echo "shutting down terminal in 10 seconds" 
exit 10

however the terminal stay's open.

i tried it to exit immediately (without the 10 after exit)
but that also wont work

tried &exit without result
tried && exit without result

cant find the solution trough google, so i hope somebody can help me here.

thx

(i am trying to learn scripting a bit, and i am fussing around with this one: http://bash.cyberciti.biz/guide/Hello,\_World!_Tutorial to make it do other stuff, just to try to understand the scripting more)

The "exit 10" just tells the script to return an exit status "10". It does not mean it will close the terminal in 10 seconds.

You can source the script so that it runs in the current shell:

Example:

[root@atlas tmp]# ps -p $$			## Current shell is bash
  PID TTY          TIME CMD
12755 pts/0    00:00:00 bash

[root@atlas tmp]# ksh				## Change to Korn shell (parent process is bash)
# ps -p$$
  PID TTY          TIME CMD
12809 pts/0    00:00:00 ksh

# /tmp/script.sh				## Runs the script in a subshell
Hello, World!
Knowledge is power.
shutting down terminal in 10 seconds

# ps -p$$					## Upon execution, shell is still KSH
  PID TTY          TIME CMD
12809 pts/0    00:00:00 ksh

# . /tmp/script.sh				## Now force the script to run in current shell
Hello, World!
Knowledge is power.
shutting down terminal in 10 seconds

[root@atlas tmp]# ps -p $$			## KSH got closed. Current shell is now bash.
  PID TTY          TIME CMD
12755 pts/0    00:00:00 bash

say what?
your explanation is probably 100% correct, but i don't understand a thing of it :stuck_out_tongue:

but when i just use exit i think it should exit the terminal, or am i that wrong?

The shell is closed, not the terminal.

A terminal is -strictly speaking- hardware attached to a computer that provides basic input/output features. This definition however is now pretty much historical as nowadays terminal emulators are much more common and popular (putty, xterm, etc).

Short answer:

Use:

. ./script

instead of:

./script

EDIT: Since you're following Nixcraft's tutorials, you might want to have a look at this one for a brief explanaiton on subshells: What is a Subshell? - Linux Shell Scripting Tutorial - A Beginner's handbook