LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   restoring bashrc (https://www.linuxquestions.org/questions/linux-newbie-8/restoring-bashrc-136891/)

agentneo 01-20-2004 06:46 PM

restoring bashrc
 
i messed up my etc/bashrc file (red hat 9) and im not sure what to do.

It was an accident - i was just adding a single line - and when i removed it the file still messed things up. I was wondereing if there was anyway to restore it to the way it was before ... fix the problem ... or get a new file. here is the code and the error:

Code:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.


if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    if [ -x /usr/bin/tput ]; then
      if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal
        stty erase `tput kbs`
      elif [ -x /usr/bin/wc ]; then
        if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb" terminal
          stty erase `tput kbs`
        fi
      fi
    fi
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
   
    if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
            if [ -r "$i" ]; then
                . $i
            fi
        done
    fi
fi
# vim:ts=4:sw=4

when i login to SSH i get this:

Last Login: bla bla bla
: command not found
: command not found
: command not found
: command not found
: command not found
'bash: etc/bashrc: line 28: syntax error near unexpected token 'in
'bash: etc/bashrc: line 28: ' case $TERM in

after that the command line starts with: "-bash-2.05b#" (no quotes), and nothing works

darthtux 01-20-2004 09:29 PM

The original is in
/etc/bashrc

cp /etc/bashrc ~/.bashrc

First backup

cp ~/.bashrc ~/.bak.bashrc

agentneo 01-21-2004 04:14 PM

alright that helps me out a bit - but i really needed to repair my already damaged bashrc file. It has a syntax error on line 28

mikshaw 01-21-2004 06:15 PM

It seems like a syntax error, though I don't see one....unless "xterm*" might end up being "xterm -flag something" with spaces in it. In this case you might want to use quotes in

case "$TERM" in

As a simple recommendation, try not to edit system-wide files that can be modified via a user-specific file. In this case, ~/.bashrc could be played with all you want, and if something gets messed up you can always cp -f /etc/bashrc ~/.bashrc

agentneo 01-21-2004 07:50 PM

i coult not find ~/.bashrc on the SSH FTP. Do i need to make it or is it just hidden from site?

EDIT: the thing i found weird is that i did not edit line 28 in any way. I simply added a new line at the top of the file, and then removed it when i saw the error.

mikshaw 01-21-2004 08:08 PM

~/.bashrc is probably not going to be created automatically. What I'd do in the future if you dont already have a .bashrc backup is to copy the /etc/bashrc (or similarly named file) to ~/.bashrc and edit that instead of editing the system-wide rc file. Another thing you could do is modify the /etc/skel/.bashrc file. This is the one that is added to all new users' home directory.

As for the weird thing, did you log out after making the changes? .bashrc is only referenced when you open a new shell. If you're still in the same shell, even if you modified the file, it'll use the old settings.

agentneo 01-21-2004 10:13 PM

yes i know ive learend my lesson ... but i didnt really modify the file thats why it seems like i should be able to get it back ...

i just need to restore my etc/bashrc file to something that will work without a syntax error and i will be all set.

darthtux 01-21-2004 10:40 PM

Here's mine from Red Hat 9

Code:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    if [ -x /usr/bin/tput ]; then
      if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal
        stty erase `tput kbs`
      elif [ -x /usr/bin/wc ]; then
        if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb" terminal
          stty erase `tput kbs`
        fi
      fi
    fi
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
   
    if [ "x$SHLVL" != "x1" ]; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
            if [ -r "$i" ]; then
                . $i
            fi
        done
    fi
fi
# vim:ts=4:sw=4


agentneo 01-22-2004 03:52 PM

yes thats exactly what i have but i still have a syntax error on the that one line.

this is getting very frustrating :cry:

Bebo 01-22-2004 04:09 PM

I just copied-n-pasted your script from your first post, and ran it. No problem whatsoever. What happens if you do the same?

agentneo 01-22-2004 05:37 PM

same problem ...

think its something out side the file effecting it?

Bebo 01-22-2004 05:50 PM

Maybe... I just read your post a bit more carefully, and saw that you wrote that you added a line at the top of the script, and then removed it. Isn't the first line in a script supposed to begin with #!/bin/bash, or whatever shell it's written in? Try adding that to the top of the script; it might even work with #!/bin/sh.

(If your own shell is set to bash, then it might be that the script is supposed to work anyway, so this idea might not work out.)


All times are GMT -5. The time now is 12:43 PM.