Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This problem I have for a long time. After running terminal .profile, and .bashrc file doesn`t work (are not executed). Could you indicate where should I looking form a source of problem?

share|improve this question

migrated from stackoverflow.com Sep 26 '12 at 8:36

This question came from our site for professional and enthusiast programmers.

    
check whether this files have a proper permissions –  shuvalov Aug 14 '10 at 17:48
    
yes... you are right the reason was really stupid - incorrect permissions chmod +x ~/.profile and everything is working well. –  michaltaberski Aug 14 '10 at 18:27
1  
@xTrol: That doesn't make sense, ~/.profile doesn't require execute permission. (The shell sources it, it doesn't execute it). Try chmod -x ~/.profile and see if it still works. –  Keith Thompson Nov 4 '11 at 0:15
add comment

5 Answers

I had a similar problem with my .profile not being run. It turns out (as explained in this Apple StackExchange answer) that if you have .bash_profile or .bash_login files, then your .profile will be ignored by bash.

share|improve this answer
2  
My issue was I installed Python which automatically created a .bash_profile file which caused my .profile not to run. –  SharpPer Apr 12 '12 at 17:08
5  
This answer helps me. .bash_login was added after I installed rvm. –  Neevek Aug 10 '12 at 16:34
add comment

I guess this Q&A should go to Superuser, but anyway:

According to the section INVOCATION of the man page,

  • /etc/profile and ~/.profile is read for an interactive login shell, and
  • ~/.bashrc is read for an interactive non-login shell.

If your other UNIX machine automatically read ~/.bashrc even for an interactive login shell, that's because the system-wide /etc/ profile has a line which reads ~/.bashrc. OS X's system-wide /etc/profile doesn't have one.

So, if you want to run ~/.bashrc even for an interactive login shell, you need to include a line

. ~/.bashrc

in your ~/.profile.

share|improve this answer
add comment

Try sourcing them "by hand":

source ~/.profile

and see what happens. Note that, as others have pointed out, .profile is sourced by login shells, .bashrc by non-login shells; so try one or the other, not both.

share|improve this answer
add comment

In your terminal preferences, check in the 'Startup' pane. You have options:

Shells open with:

  • Default login shell (/usr/bin/login)
  • Command (complete path)

I have 'default' chosen...if you have the custom command chose, that may be a factor.

The next point to check is whether the shell is started as a login shell. When I do a ps listing, I see:

  PID TTY           TIME CMD
24088 ttys000    0:00.03 -sh
24614 ttys001    0:00.03 -sh
25127 ttys002    0:00.05 -sh
35544 ttys003    0:00.08 -sh
40926 ttys004    0:00.03 -sh

The key point here is the '-' in front of the shell name; that tells the shell to run through the profile and related stuff. If you don't see that in your current windows, you may need to diddle with the settings until you do.

The settings pane in the terminal preferences also lists a shell option. I have /bin/sh listed in mine.


You should not need this

If the worst comes to the worst, you can do as I did on some other uncooperative systems in times past - I created a program 'loginsh' which I could run from windows, and it in turn would execute my chosen shell with the '-' prefix to tell it to work as a login shell.

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "stderr.h"
#include "jlss.h"

#ifndef DEFAULT_SHELL
#define DEFAULT_SHELL   "/bin/sh"
#endif /* DEFAULT_SHELL */

#ifndef MAX_SHELLBASENAME
#define MAX_SHELLBASENAME   256
#endif /* MAX_SHELLBASENAME */

#ifndef lint
static const char sccs[] = "@(#)$Id: loginsh.c,v 4.2 2005/06/22 19:44:07 jleffler Exp $";
#endif

int main(int argc, char **argv)
{
    char     *shell;
    char      shellname[MAX_SHELLBASENAME];

    err_setarg0(argv[0]);

    /* Which shell to use? */
    if ((shell = getenv("SHELL")) == (char *)0)
        shell = DEFAULT_SHELL;

    /* Set up argv[0] in new argument list; reuse old argv space */
    shellname[0] = '-';
    strcpy(&shellname[1], jlss_basename(shell));
    argv[0] = shellname;

    /* Execv must work -- the shell must be an executable program */
    execv(shell, &argv[0]);
    err_syserr("cannot execute shell %s\n", shell);

    /* NOTREACHED */
    return(EXIT_FAILURE);
}

(The "stderr.h" header and 'err_*' routines are an error reporting package I use everywhere. The jlss_basename() function is basically the same as system provided versions such as are found in POSIX <libgen.h>.)

share|improve this answer
add comment

Good information above, but thought I'd share some specifics on the problem I had and the solution I found.

The need: Add a directory to PATH on OSX 10.8 (ML).

The problem: Guidance is often "mod the .profile in your home directory". A bit confusing since, by default, this file doesn't exist on OSX. Doubly confusing because once you add an export statement to append the new directory to the existing PATH ... it doesn't work. Covered above.

The solution: I added the export statement to my .bash_profile (also in the home directory).

I'm sure there are many ways to skin this cat. This one worked for me. Somewhat confidence inspiring: the .bash_profile already existed and I could see that other installed software (e.g. Ruby) had modified it. If there's a better solution I'll be glad to hear about it!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.