Segmentation fault with bash?

Discussion in 'Mac Programming' started by pabetism, Jun 22, 2012.

  1. pabetism macrumors newbie


    Jun 22, 2012
    I want to add aliases to my terminal, so I wondered around the internet until I figured out how.

    i put a .bashrc in my home folder that looks like this:

    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"


    alias lxplus="ssh"
    alias home="cd ~/"

    That is the only thing i've changed about bash and now when I type the command bash in terminal, i get the error message:

    Segmentation fault: 11

    OS 10.7.4
  2. chown33 macrumors 604

    Aug 9, 2009
    Look up recursion.

    Then don't do that.
  3. pabetism, Jun 22, 2012
    Last edited: Jun 22, 2012

    pabetism thread starter macrumors newbie


    Jun 22, 2012
    Thank you for your profound insight. If you would, please, inform unto the ways of your vast compendium of knowledge. Bestow unto me not the mundane knowledge that something is wrong, but the knowledge of how to fix it, for I know nothing of your ways, oh most gracious poster of truth.

    also, what's the difference between what I have and this (which is NOT recursive):

    if [ -f /etc/bashrc ]; then
    . /etc/bashrc # --> Read /etc/bashrc, if present.

    (taken from


    Is it because I put it in my home folder... cause that would make a lot of sense....
    Maybe I should back off on the hubris for a while, eh?
  4. jweinraub macrumors 6502


    Jun 26, 2007
    Sol III
    you are calling the function from within the function, that is recursion.


    you do not need that in your .bashrc anyway.

    here is mine...

    from linux but it is still the same nonetheless

    # .bashrc
    # User specific aliases and functions
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'
    alias vi=vim
    export PS1="[\u@\h \W]# "
  5. subsonix macrumors 68040

    Feb 2, 2008

    What that does is to first check if there is a bashrc in /etc, and if there is, use that instead.

    You are using $HOME/.bashrc, which refers to the very file you have shown here. Basically saying, "if this file exist, then use this file".
  6. chown33 macrumors 604

    Aug 9, 2009
    The difference between the two is simple:
    yours has $HOME/,
    theirs has /etc/

    If the .bashrc in your $HOME directory includes the contents of the one in /etc, then that is, as you said, not recursive. Unless your $HOME is set to /etc, which is only going to happen if you alter it.

    To understand the recursion problem, simply walk through what yours is asking bash to do:
    Check for a file named $HOME/.bashrc, and interpret its contents.
    What's the first thing in the file named $HOME/.bashrc?
    Check for a file named $HOME/.bashrc, and interpret its contents.
    If you don't see how that forms an infinite loop, then you didn't look up or understand recursion.

    Or simply explain how you got what you posted.

    If you'd pointed to that article in your first post, and said you'd modified it without understanding what it did, then I would have explained the recursion problem. Is it was, with no other context to interpret what you posted, I made a quick reply that, upon further investigation, should have led you to an answer. But yeah, if you don't understand recursion, then you should probably just say that instead of deploying sarcasm.
  7. pabetism thread starter macrumors newbie


    Jun 22, 2012
    Thanks for pointing to my problem, and that it was a recursion issue.

    That being said, I know what recursion is. What I didn't know was how to parse the .bashrc file. I'm a newb, and I know it. This stuff is kind of intimidating at first, an your comment (on its surface) seemed unhelpful and demeaning. My knee jerk reaction (to knock a gift horse in the mouth) was a poor decision. It was only after I read your comment that I found the .bashrc I referenced (it was a different site that had the home reference), and with It's comment, I was able to understand the syntax (though not after a bit of a break and coming back fresh). It was then that I understood how I had doomed myself to a recursive loop.

    So, thanks for the heads up on what was going on. Next time I'll be a bit more patient with the advice I receive.


    Thanks for the explanation!

Share This Page