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:
Code:
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.
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:
Code:
[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
Last edited by verdepollo; 09-01-2011 at 02:07 PM..
Reason: Add clarification
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).
Hello,
I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using,
#!/bin/bash
# main backup location, trailing slash included
backup_loc="/Volumes/Archive_Volume/00_macos_backup/"
# generic backup function
function backup {... (12 Replies)
Hi,
In one of the circumstances, my manager asked my password and opened unix terminal (Putty) with my user credentials. Its been more than 2 days that terminal is opened (saw it through finger command). How do I close that terminal which is not opened in my pc. I'm very uncomfortable of the... (11 Replies)
I am new to shell scripting.
I tried to run a simple shell script using Cygwin terminal in Win XP env.
The script I have written is as follows -
#!/bin/bash
a=5
] && echo "true" || echo "false"
But when I execute the script, getting some confusing error. The error I am getting are - ... (3 Replies)
Is there a trick to closing a mac terminal with a command? I would think you could just type exit into your terminal but that doesn't work. I also tried quit and close just for the hell of it and that didn't work either. Does anyone know what the command is? (1 Reply)
Hi. !
When I use the 'NOHUP' along with the '&', the process will be running in the background. Even when I attempt to close (Meaning 'EXIT') the session (say PUTTY in this case), it wont exit unless the process is completed.
But, say when I forcefully terminate the session (SHUT DOWN the... (2 Replies)
Hello everyone
I have a user on my server, Aix 5.3 TL9 sp4. Weeks ago I dont have a problem but today the user cannot log in. let me explain.
Me with root user I can change his password. then I log in with the user and I can change the password and the terminal close. Im using ssh.
But... (2 Replies)
Hi,
I'm new here so please excuse any stupidity that occurs in my post :P
My situation:
Have a java program which I have to run a ridiculous amount of times and put the output data into a text file.
Thought the easiest way to do this would be to delve into the world of scripts.
I am at home... (1 Reply)
suppose we have a file
ab
81
and another file
exec < $1
while read line
do
ssh root@172.16.1.$line
done
while running the command
sh file.sh ab
output display as shown
Pseudo-terminal will not be allocated because stdin is not a terminal.
root@172.16.1.81's password:
after... (3 Replies)
I'm trying to figure out how I can run a script "myScript.sh" in such a way that if my remote network connection gets disconnected, the script doesn't stop functioning.
Right now I log in, run "./myScript.sh" and watch my output get pumped to a log file for about 10 hours. Only problem is that... (3 Replies)