views:

153

answers:

3

Hi,

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?

A: 

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.

Yuji
A: 

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>.)

Jonathan Leffler
A: 

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.

Gordon Davisson