PDA

View Full Version : Segmentation fault with bash?




pabetism
Jun 22, 2012, 01:06 PM
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"
fi

#
#
#

alias lxplus="ssh asachs@lxplus.cern.ch"
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



chown33
Jun 22, 2012, 01:35 PM
i put a .bashrc in my home folder that looks like this:

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

#
#
#

alias lxplus="ssh asachs@lxplus.cern.ch"
alias home="cd ~/"

Look up recursion.

Then don't do that.

pabetism
Jun 22, 2012, 01:50 PM
Look up recursion.

Then don't do that.

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

(taken from http://tldp.org/LDP/abs/html/sample-bashrc.html)

----------

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?

jweinraub
Jun 22, 2012, 02:22 PM
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]# "

subsonix
Jun 22, 2012, 02:34 PM
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.
fi

(taken from http://tldp.org/LDP/abs/html/sample-bashrc.html)[COLOR="#808080"]


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

chown33
Jun 22, 2012, 02:43 PM
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.
fi

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.


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

pabetism
Jun 24, 2012, 06:34 PM
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.

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.

----------

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

Thanks for the explanation!