Results 1 to 3 of 3
so I'm really new to shell scripting and I've been studying and playing around trying to write a couple of useful shell scripts for myself. today I wrote my first, ...
- 11-04-2007 #1
exit status issues from a noob
so I'm really new to shell scripting and I've been studying and playing around trying to write a couple of useful shell scripts for myself. today I wrote my first, original and applicable start up script to open the terminal upon login. the problem is that upon reboot the command opens several successive terminals and keeps repeating itself until an infinite number of terminal windows are open. this sucks and I would like to fix it. the following is a copy of my script
#!bin/bash
#this program ought to open the terminal for me upon startup...cross your
#fingers.
gnome-terminal
#now let's see if I can teach this dog a new trick
echo "Hello Cyrus!"
#end of script.
the goal being that a terminal window would open and say hello to me (because I'm just that kind of nerd)
I'm sure it's a simple solution and I've searched several templates and examples hoping to find a clue, but like I said, I'm really new to this.
anybody have any info that could point me in the right direction???
- 11-04-2007 #2
First, your sh-bang line needs to read:
#!/bin/bash
Second, where are you calling the script from - ~/.bash_profile? ~/.profile? ~/.bashrc?
You see what the problem is here? When you open a terminal, you're telling it to open a gnome-terminal. For every gnome-terminal that opens, you're telling it to open another on top of it.
- 11-04-2007 #3
To be a bit more specific:
Every time a new terminal is opened (be it through logging in, ssh'ing in, switching user, running a terminal program, etc.), one of ~/.bash_profile or ~/.bashrc is run (assuming Bash shell: tcsh, for instance, has its own files). Therefore, as anomie says, you run gnome-terminal and it reads ~/.bashrc, which runs gnome-terminal, which reads ~/.bashrc, and so on, ad infinitum.
There is another flaw here. Your system is going to try to run gnome-terminal whenever you login anywhere, even if that was in text mode.
The solution is to, instead of executing this in ~/.bash_profile or ~/.bashrc is to execute it upon X login (or X startup). Well, there are two ways to go about this. The first is to go to Gnome's preferences, to the "Sessions" option, and tell it to launch a gnome-terminal on startup. The second is to put the command instead into ~/.xprofile. The commands in this file are executed after X starts up, which is exactly what you want. In your case, you could either invoke the script you've written, or put those commands directly into the ~/.xprofile file. Make sure that you put an '&' after the command call, so that the script is backgrounded and other commands can run instantly.
The last thing to discuss is your echo message. This is going to print "Hello Cyrus!" to the terminal that controls the script. Well, in this particular case, the script is being executed by whatever is executing ~/.xprofile, and that has no controlling terminal (unless, again, you were running X manually). So this message will never be seen. What you want to do is to have the gnome-terminal instance print the message. You can do this very easily, by saying:
This tells gnome-terminal to run the given command, rather than just opening and waiting.Code:gnome-terminal -e 'echo "Hello Cyrus!"'
Does all of that make sense?DISTRO=Arch
Registered Linux User #388732


Reply With Quote