I wanted to make a script which ran automatically on login so I put it into the file ~/bash.profile, but it didn't run. When I put it in bashrc, it ran on opening a terminal.

What I was doing in the script was accessing a file in the pictures folder. I just added ./script.sh in ~/.bash_profile. How to make it run on login?

I'm using Unity on Ubuntu 11.10.

  • Please post the script here for clarification. You should put things that should happpen on login time in the file ~/.bash_profile AFAIK. – user13742 Feb 24 '12 at 18:58
  • Oh, and make sure it is executable; run chmod +x script.sh in case you haven't. – user13742 Feb 24 '12 at 19:04
  • yes the script is executable – user1065734 Feb 24 '12 at 19:11
  • i did tell that it ran in .bashrc – user1065734 Feb 24 '12 at 19:12
  • 2
    ~/.bash_profile always runs when you log in in text mode (if your login shell is bash), but depending on the distribution and desktop environment, it may or may not run when you log into the GUI. How do you log in (e.g. gdm, kdm, text console, …), what desktop environment or session mananger do you use (e.g. Gnome, KDE, .xsession, …), and under what distribution (e.g. Ubuntu 11.10, Fedora Core 15, OpenBSD 5.0, …)? – Gilles 'SO- stop being evil' Feb 24 '12 at 19:14

.profile and .bash_profile are files that are sourced by bash when running as a login shell such as when logging in from the Linux Text console or using SSH. They are not sourced when loading a new shell from an existing login such as when opening a new terminal window inside Unity or other graphical environment. .bashrc on the other hand is only sourced for non-login shells, though sometimes distros will source .bashrc manually from within the default .bash_profile. One workaround is to change Gnome Terminal to load the shell as a login shell from it's profile preferences, but then that would run every time you open up a new terminal window. Another option is to add it to the list of Startup Applications as suggested by @jrg.

|improve this answer|||||
  • ok then, can i add the script in startup application by terminal like is there any command to add a script to add in startup application – user1065734 Mar 3 '12 at 13:37

I'm going to paraphrase from another answer, but I'll include all the basics.

You stated that you're using Unity, so search for and then open the program Startup Applications in the dash.

Then, click "Add".

enter image description here

Now, enter in the details of the script:

enter image description here

changing my example details with your own details

Click "Add" and you should be all set!

|improve this answer|||||
  • i did the same but the script doesnt work properly – user1065734 Feb 25 '12 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.