Bash is broken Topic is solved

Need help with your Linux distro? All questions are good - not all answers are -but we try

Moderator: jkerr82508

User avatar
dedanna1029
Sound-Berserk
Posts: 8780
Joined: 14 Mar 2010, 20:29
Contact:

Bash is broken

Postby dedanna1029 » 13 Nov 2012, 23:50

Not sure how to get this straightened out.

I noticed after I mounted my /home folder in CentOS 6.2 (post-install), that all I was getting was the bash 4.1 prompt. So, I checked out ~/. and there was no .bashrc or .bash_profile, so I created them via here. After I did, there were "anomalies", such as no prompt at all for plain su, yet a prompt for su -. Also when using just plain su, there was a /home/dedanna/bin: path added when I would echo $PATH, but not when I'd su - (note the difference; the dash). I can no longer log into root now, at all, not with terminal, not with anything, and after a reboot, I'm back to the bash 4.1 prompt, because I reset the files in ~/, thinking they're screwed.

I tried various fixes in the files, they wouldn't fly no matter what I did. Can someone please check these out and see what I have to do for these? Maybe the paths are wrong? Here's what I had in each:

In my /home, I edited them to this:

Code: Select all

# .bashrc

# User specific aliases and functions

# Source global definitions
#if [ -f /etc/bashrc ]; then
#   . /etc/bashrc
#fi

    bash_prompt_cmd() {
    RTN=$?



    smiley() {
        if [ $1 == 0 ] ; then
    echo ":)"
        else
    echo ":)"
           fi
        }
    smileyc() {
        if [ $1 == 0 ] ; then
    echo $GREEN
    else
    echo $RED
           fi
        }
    if [ $(tput colors) -gt 0 ] ; then
    RED=$(tput setaf 1)
    GREEN=$(tput setaf 2)
    RST=$(tput op)
    fi
    smiley=$(smiley $RTN)
    smileyc=$(smileyc $RTN)
            local CY="\[\e[1;31m\]" # Each is 12 chars long
            local BL="\[\e[1;34m\]"
            local WH="\[\e[1;37m\]"
            local BR="\[\e[0;33m\]"
            local RE="\[\e[1;31m\]"
            local PROMPT="${CY}$"
            [ $UID -eq "0" ] && PROMPT="${RE}#"

            # Add the first part of the prompt: username,host, and time
            local PROMPT_PWD=""
            local PS1_T1="$BL.:[ $CY`whoami`@`hostname` $BL: $CY\t $BL:$CY "
            local ps_len=$(( ${#PS1_T1} - 12 * 6 + 6 + 4 )) #Len adjust for colors, time and var
            local PS1_T2=" $BL]:.\n\[\$smileyc\]\$smiley\[$RST\] "
            local startpos=""

            PROMPT_PWD="${PWD/#$HOME/~}"
            local overflow_prefix="..."
            local pwdlen=${#PROMPT_PWD}
            local maxpwdlen=$(( COLUMNS - ps_len ))
            # Sometimes COLUMNS isn't initiliased, if it isn't, fall back on 80
            [ $maxpwdlen -lt 0 ] && maxpwdlen=$(( 80 - ps_len ))

            if [ $pwdlen -gt $maxpwdlen ] ; then
                    startpos=$(( $pwdlen - maxpwdlen + ${#overflow_prefix} ))
                    PROMPT_PWD="${overflow_prefix}${PROMPT_PWD:$startpos:$maxpwdlen}"
            fi
            export PS1="${PS1_T1}${PROMPT_PWD}${PS1_T2}"
    smiley=$(smiley $RTN)
    smileyc=$(smileyc $RTN)
            local CY="\[\e[1;31m\]" # Each is 12 chars long
            local BL="\[\e[1;34m\]"
            local WH="\[\e[1;37m\]"
            local BR="\[\e[0;33m\]"
            local RE="\[\e[1;31m\]"
            local PROMPT="${CY}$"
            [ $UID -eq "0" ] && PROMPT="${RE}#"

            # Add the first part of the prompt: username,host, and time
            local PROMPT_PWD=""
            local PS1_T1="$BL.:[ $CY`whoami`@`hostname` $BL: $CY\t $BL:$CY "
            local ps_len=$(( ${#PS1_T1} - 12 * 6 + 6 + 4 ))
       #Len adjust for colors, time and var
            local PS1_T2=" $BL]:.\n\[\$smileyc\]\$smiley\[$RST\] "
            local startpos=""

            PROMPT_PWD="${PWD/#$HOME/~}"
            local overflow_prefix="..."
            local pwdlen=${#PROMPT_PWD}
            local maxpwdlen=$(( COLUMNS - ps_len ))
            # Sometimes COLUMNS isn't initiliased, if it isn't, fall back on 80
            [ $maxpwdlen -lt 0 ] && maxpwdlen=$(( 80 - ps_len ))

            if [ $pwdlen -gt $maxpwdlen ] ; then
                    startpos=$(( $pwdlen - maxpwdlen + ${#overflow_prefix} ))
                    PROMPT_PWD="${overflow_prefix}${PROMPT_PWD:$startpos:$maxpwdlen}"
            fi
            export PS1="${PS1_T1}${PROMPT_PWD}${PS1_T2}"
    }
    PROMPT_COMMAND=bash_prompt_cmd


Code: Select all

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:.
BASH_ENV=$HOME/.bashrc
USERNAME="dedanna"

export USERNAME BASH_ENV PATH


I did the same for root's, except changed the username line to dedanna for my /home, left it as root for root's. This is all very strange to me. I've edited both before, with no problem.

Here's a kicker for you, not sure if it has anything to do with it. I had to, post-install, chown my /home folder to me, because of this error. I don't know if that has anything to do with this, but with it being a permissions thing, I'm figuring it might have. I used:

Code: Select all

chown -R dedanna:dedanna /home/dedanna


Not being able to get into root right now from terminal or anywhere else at all is ending up to be a royal pain - I can't install anything, I can't do anything I need to. This also puts me in a vicious cycle wherein I can't reset those two files in root. When I try logging into root, it hangs for a minute or two, then goes right back to regular user. This is from Ctl+Alt+F2, from terminal in the desktop, and when I try logging in directly from gdm.

Thanks.
Last edited by dedanna1029 on 19 Nov 2012, 00:23, edited 1 time in total.
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Bash is broken  Topic is solved

Postby viking60 » 14 Nov 2012, 14:27

Relatively big question there so here is a start

Code: Select all

[berserk@centos ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
   . /etc/bashrc
fi

# User specific aliases and functions

That is what it looks like if you do not play with it....
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
dedanna1029
Sound-Berserk
Posts: 8780
Joined: 14 Mar 2010, 20:29
Contact:

Re: Bash is broken

Postby dedanna1029 » 15 Nov 2012, 00:25

That, I didn't play with, until I saw an example of it, changed to that. Remember, it wasn't even there in /home until I created it. I'll change it to what you have there, and then we'll go from there. Thanks.
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html

User avatar
dedanna1029
Sound-Berserk
Posts: 8780
Joined: 14 Mar 2010, 20:29
Contact:

Re: Bash is broken

Postby dedanna1029 » 15 Nov 2012, 21:07

Now, the problem lies, how do I get into root to check out its .bashrc?

Thanks.

Edit: Never mind, am in via the livedvd.

Edit2: That did it. It was root's .bashrc - I'd missed a line. :P

Thank you. Just needed a pointer on where to look.
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html


Return to “Help”