LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2004, 06:46 PM   #1
agentneo
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Rep: Reputation: 0
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
 
Old 01-20-2004, 09:29 PM   #2
darthtux
Senior Member
 
Registered: Dec 2001
Location: 35.7480° N, 95.3690° W
Distribution: Debian, Gentoo, Red Hat, Solaris
Posts: 2,070

Rep: Reputation: 47
The original is in
/etc/bashrc

cp /etc/bashrc ~/.bashrc

First backup

cp ~/.bashrc ~/.bak.bashrc

Last edited by darthtux; 01-20-2004 at 09:31 PM.
 
Old 01-21-2004, 04:14 PM   #3
agentneo
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 01-21-2004, 06:15 PM   #4
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
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
 
Old 01-21-2004, 07:50 PM   #5
agentneo
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
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.

Last edited by agentneo; 01-21-2004 at 07:55 PM.
 
Old 01-21-2004, 08:08 PM   #6
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
~/.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.
 
Old 01-21-2004, 10:13 PM   #7
agentneo
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 01-21-2004, 10:40 PM   #8
darthtux
Senior Member
 
Registered: Dec 2001
Location: 35.7480° N, 95.3690° W
Distribution: Debian, Gentoo, Red Hat, Solaris
Posts: 2,070

Rep: Reputation: 47
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

Last edited by darthtux; 01-21-2004 at 10:44 PM.
 
Old 01-22-2004, 03:52 PM   #9
agentneo
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
yes thats exactly what i have but i still have a syntax error on the that one line.

this is getting very frustrating
 
Old 01-22-2004, 04:09 PM   #10
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 31
I just copied-n-pasted your script from your first post, and ran it. No problem whatsoever. What happens if you do the same?
 
Old 01-22-2004, 05:37 PM   #11
agentneo
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
same problem ...

think its something out side the file effecting it?
 
Old 01-22-2004, 05:50 PM   #12
Bebo
Member
 
Registered: Jul 2003
Location: Göteborg
Distribution: Arch Linux (current)
Posts: 553

Rep: Reputation: 31
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.)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
where is bashrc ? Kanaflloric Slackware 12 10-06-2007 02:47 PM
.bashrc help shanenin Linux - Software 4 02-14-2004 06:17 PM
no .bashrc? mattman Slackware 6 06-10-2003 03:59 PM
.bashrc roofy Slackware 7 05-06-2003 01:32 PM
.bashrc prasad Linux - General 1 04-14-2001 09:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration