.profile not working?

Discussion in 'Mac Programming' started by CMT, Oct 18, 2010.

  1. CMT
    macrumors member

    CMT

    Joined:
    Aug 24, 2009
    #1
    I created a .profile in my home directory with this line:

    export PATH=.:$PATH:~/bin
    alias h history

    But it look that it has no effect. Any ideas on what can be blocking? (I'm new to working with the Bash Shell)

    Thanks!
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    1) I think .bash_profile is what you want.
    2) Don't add . to your path.

    -Lee
     
  3. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    When you say "it has no effect" what have you done? Have you created a new shell/terminal window? Changes to the .profile don't effect currently running shells.
     
  4. CMT
    thread starter macrumors member

    CMT

    Joined:
    Aug 24, 2009
    #4
    I put the same lines in .bash_profile, and the PATH extension worked perfectly.

    However, now I get this message:

    -----------------------------------
    -bash: alias: h: not found
    -bash: alias: history: not found
    -----------------------------------

    Hmm, just curious, why not? I did that as a initial configuration as recommended in the book I'm reading. (Beginning Show Leopard Programming)

    Of course, I know that.

    Thanks!
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  6. CMT
    thread starter macrumors member

    CMT

    Joined:
    Aug 24, 2009
    #6
    So we have a typo in the Book!

    Thanks a lot, worked perfectly.
     
  7. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    Or it assumes a different shell where the syntax given works?
     
  8. macrumors 603

    Joined:
    Aug 9, 2009
    #8
    Have you checked for a website associated with the book, for any corrections to printed errors?
     
  9. CMT
    thread starter macrumors member

    CMT

    Joined:
    Aug 24, 2009
    #9
    Probably not. The book was made to work with the standard bash shell… (this is all I now until now, I'll continue reading)

    I'll check that. The book is quite recent. It cover a lot of things in more than 600 pages. So I think it's natural that an errata starts to appear.

    Thank you.
     
  10. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #10
    While OS X is generally a "single-user" system, having . in your PATH in any UNIX is considered risky, because someone could place a dangerous executable named something like ls in some random directory on the system. Once you cd into that directory, when you do an ls to take a look maybe your home directory is going to be wiped out, etc. In the case of OS X there's probably not a "someone" that would do this like they might on a multi-user UNIX, but it's just "best practice". Typing ./ before commands isn't too hard, and you're likely going to be hitting up arrow to get to the command in your history more often than manually typing it.

    It's a bit disappointing that this recommendation would be published. Hopefully no one breaks into your system, but if they got in via some under-privileged account, but dropped an executable somewhere that you (using a privileged account) might run then a pretty low-impact exploit becomes much more dangerous.

    -Lee
     
  11. CMT
    thread starter macrumors member

    CMT

    Joined:
    Aug 24, 2009
    #11
    Thanks Lee for the recommendation, clarified a lot.

    Right at this moment I could discover why .profile didn't worked initially:

    From this Unix FAQ http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup

    Bash Startup Files
    When a "login shell" starts up, it reads the file "/etc/profile" and then "~/.bash_profile" or "~/.bash_login" or "~/.profile" (whichever one exists - it only reads one of these, checking for them in the order mentioned).

    After running a ls -A, I discovered there was indeed a file in my home directory named .bash_login. It contained only one line, adding php directory to the PATH.

    So, it was blocking to read .profile. Once I added .bash_profile, this last one was chose to be read.

    To make everything work as expected, I just added the same line in .bash_login to .profile and deleted that file.

    Thank you a lot for the help.
     

Share This Page