LinuxQuestions.org
Visit Jeremy's Blog.
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 03-01-2009, 01:22 AM   #1
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Rep: Reputation: 17
bash's source command doesn't work with .bashrc -- solved


"source .bashrc" didn't have any effect after I made some changes to .bashrc, then I tried to make some experiments to figure out what is wrong, and got the following interesting but weird results:

1. I add "echo hello" to the beginning of .bashrc and source it, no "hello" being printed.

2. I renamed ".bashrc" to "test_source" (just an arbitrary name) and ran "source test_source", surprisingly, it worked, I got the desired result and "hello" was printed on the screen.

3. I ran "bash" in current shell, and got the same result as 2.

So it seems that "source" just don't like the name ".bashrc" , Any ideas? (I'm using Ubuntu 8.10)

Thanks!

Last edited by crs_zxf; 03-06-2009 at 07:30 PM. Reason: solved
 
Old 03-01-2009, 03:57 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Quote:
Originally Posted by crs_zxf View Post
"source .bashrc" didn't have any effect after I made some changes to .bashrc, then I tried to make some experiments to figure out what is wrong, and got the following interesting but weird results:

1. I add "echo hello" to the beginning of .bashrc and source it, no "hello" being printed.

2. I renamed ".bashrc" to "test_source" (just an arbitrary name) and ran "source test_source", surprisingly, it worked, I got the desired result and "hello" was printed on the screen.

3. I ran "bash" in current shell, and got the same result as 2.

So it seems that "source" just don't like the name ".bashrc" , Any ideas? (I'm using Ubuntu 8.10)

Thanks!
You might have a look here. There is a solution in the thread.
Google is your friend
https://bugs.launchpad.net/ubuntu/+s...sh/+bug/160405
cheers,
jdk
 
Old 03-01-2009, 05:06 AM   #3
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by jdkaye View Post
You might have a look here. There is a solution in the thread.
Google is your friend
https://bugs.launchpad.net/ubuntu/+s...sh/+bug/160405
cheers,
jdk
Unfortunately, the problem stated in that thread is different from mine, in my case, even the first line in .bashrc which is just an "echo" command isn't executed when source, and I don't have anything related to bash_completion in my .bashrc.

Anyway, thanks for your reply.
 
Old 03-01-2009, 06:30 AM   #4
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Quote:
Originally Posted by crs_zxf View Post
Unfortunately, the problem stated in that thread is different from mine, in my case, even the first line in .bashrc which is just an "echo" command isn't executed when source, and I don't have anything related to bash_completion in my .bashrc.

Anyway, thanks for your reply.
You're welcome. It's very strange. I just added
Code:
echo "hello"
as the first line of my .bashrc went to my terminal (already opened) and entered
Code:
source .bashrc
and got this:
Code:
jdkaye@Attila:~$ source .bashrc
hello
What terminal program are you running. I'm using konsole (KDE).
Cheers,
jdk
 
Old 03-01-2009, 06:31 AM   #5
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
I always run the following :-

$ . .bashrc

This will run .bashrc in the current session. You should find that this will work. Good luck.
 
Old 03-01-2009, 07:24 AM   #6
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by jdkaye View Post
What terminal program are you running. I'm using konsole (KDE).
Cheers,
jdk
I use urxvt. But I test it in both konsole and gnome-terminal, the result is the same as in urxvt.

Thanks.

Last edited by crs_zxf; 03-01-2009 at 07:30 AM.
 
Old 03-01-2009, 07:29 AM   #7
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by ArfaSmif View Post
I always run the following :-

$ . .bashrc

This will run .bashrc in the current session. You should find that this will work. Good luck.
In fact, '.' is same command as 'source', it makes no difference to run '. .bashrc'.

Thanks.
 
Old 03-01-2009, 03:31 PM   #8
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
Cat you cat .bashrc for us to see please? Thanks.
 
Old 03-01-2009, 05:33 PM   #9
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by ArfaSmif View Post
Cat you cat .bashrc for us to see please? Thanks.

Code:
# There are 3 different types of shells in bash: the login shell, normal shell
# and interactive shell. Login shells read ~/.profile and interactive shells
# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all
# settings made here will also take effect in a login shell.
#
# NOTE: It is recommended to make language settings in ~/.profile rather than
# here, since multilingual X sessions would not work properly if LANG is over-
# ridden in every subshell.

# Some applications read the EDITOR variable to determine your favourite text
# editor. So uncomment the line below and enter the editor of your choice :-)
export EDITOR=/usr/bin/vim
# export EDITOR=/usr/bin/mcedit

# For some news readers it makes sense to specify the NEWSSERVER variable here
# export NEWSSERVER=your.news.server

# If you want to use a Palm device with Linux, uncomment the two lines below.
# For some (older) Palm Pilots, you might need to set a lower baud rate
# e.g. 57600 or 38400; lowest is 9600 (very slow!)
#
# export PILOTPORT=/dev/pilot
# export PILOTRATE=115200

setterm -blength 0

if [ "`echo $PATH | grep software`" = "" ]; then
        export PATH=/usr/bin:/root:/usr/sbin:/sbin:$PATH
        export MANPATH=$MANPATH:/usr/X11R6/share/man/
        export PATH=$PATH:/home/chenrs/chenrs-mini-tools/bin:/home/chenrs/software
fi

# for app intallation
alias config-make-install='./configure && make && sudo make install'
# for mplayer
alias mp='mplayer -subcp cp936 -subfont-osd-scale 3 -subfont-text-scale 3'
alias gmp='gmplayer'
alias mplist='mplayer -playlist'
alias mps='mplayer -shuffle'
# for xset
alias xset-before='xset dpms 3600 3600 3600'
alias xset-after='xset dpms 0 0 180'
alias xset-off='xset dpms force off'
# for network
alias lprhp='lpr -P hp -o sides=two-sided-long-edge'
alias ssh-132xt='ssh xiaotong@10.10.10.132'
alias ssh-23crs='ssh chenrs@10.10.10.23'
alias ssh-48xt='ssh xiaotong@202.118.18.181'
alias ssh-10crs='ssh chenrs@ics.neu.edu.cn'
alias lftp-132xt='lftp -u xiaotong,. 10.10.10.132'
alias lftp-23crs='lftp -u chenrs,. 10.10.10.23'
alias lftp-48xt='lftp -u xiaotong,. 202.118.18.181'
alias lftp-10crs='lftp -u chenrs,123456 ics.neu.edu.cn'
# for mount 
alias mount-fat='sudo mount -o iocharset=utf8'
alias mount='sudo mount -o uid=1000,gid=100'
alias umount='sudo umount'
alias umount-sdb='sudo umount /mnt/mobile*'
alias umount-dvd='sudo umount /mnt/dvd'
alias umount-win='sudo umount /mnt/win'
# for urxvt encoding
alias gb-encoding='export LC_CTYPE="zh_CN.gb2312"; printf "\33]701;$LC_CTYPE\007"'
alias utf8-encoding='export LC_CTYPE="zh_CN.utf8"; printf "\33]701;$LC_CTYPE\007"'
# for apt
alias apt-search='apt-cache search'
alias apt-install='sudo apt-get install'
# misc
alias l='ls -alF'
alias xrar='unrar x'
alias s2ram='sudo s2ram -f'
alias ls='ls --color=always'
alias ..='cd ..'
alias export-cwd='export PATH=$PATH:$(pwd)'

# the following "bind" command is for bash vi-editing mode
bind -m vi-insert "\C-l":clear-screen
bind -m vi-insert "\C-e":vi-append-eol
bind -m vi-insert "\C-a":vi-insert-beg
bind -m vi-insert "\C-p":history-search-backward
bind -m vi-insert "\C-n":history-search-forward

export PS1="~~~~~~ \w ~~~~~~\n$ "
 
Old 03-02-2009, 12:25 AM   #10
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
Cannot see anything there that would cause a problem. I've run out of ideas sorry.
 
Old 03-02-2009, 06:09 AM   #11
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
Very odd. I just copy/pasted your output, made it my .bashrc and sourced it, and it worked fine. Then added 'echo "hello"' to the top and sourced again, and got the echo. Know that doesn't help you much!

Do you get the same problem on a non-graphical login (Ctrl+alt+F1)? Not sure whether or not that's the same program as gnome-terminal, but I guess not.
 
Old 03-02-2009, 08:59 AM   #12
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by openSauce View Post
Do you get the same problem on a non-graphical login (Ctrl+alt+F1)? Not sure whether or not that's the same program as gnome-terminal, but I guess not.
What you said makes me find another stranger problem, when I login the virtual terminal, I found .bashrc not being executed at all, then I run ". .bashrc", it took effect, after that, I tried to run it again, nothing happened except the PS1 being set to the system default (this happened in graphical enviroment too), so it seems that in my case .bashrc can only be executed once. Why? I'm totally confused.

Last edited by crs_zxf; 03-02-2009 at 09:03 AM.
 
Old 03-03-2009, 01:37 AM   #13
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
Which version of bash are you running and what distribution do you have?

I would suggest you update to the latest version of bash if you are not up to date.

Does the install of your operating system work OK other than this bizarre problem, and if it doesn't perhaps the install of the OS did not complete correctly, in which case I would reinstall and check all media before continuing.
 
Old 03-03-2009, 07:59 AM   #14
crs_zxf
Member
 
Registered: Oct 2008
Distribution: Arch Linux
Posts: 37

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by ArfaSmif View Post
Which version of bash are you running and what distribution do you have?

I would suggest you update to the latest version of bash if you are not up to date.

Does the install of your operating system work OK other than this bizarre problem, and if it doesn't perhaps the install of the OS did not complete correctly, in which case I would reinstall and check all media before continuing.
I use bash 3.2.39(1)-release in Ubuntu 8.10, and this system will automatically update itself on a regular basis.

In fact, recently I installed this system on my girlfriend's laptop, and got the same problem. I think this may be a bug of bash.

Though this problem may not be solved, thanks for your time.
 
Old 03-04-2009, 03:52 AM   #15
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
That's interesting. My bash version is bash-3.2-30.fc10.i386 which is a few steps behind yours. Any way to "go backwards"?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
~/.bashrc variable for a command? Maybe? computer_freak_8 Linux - Newbie 17 02-02-2009 07:46 PM
bashrc:command not found ukyo Linux - General 1 03-08-2005 09:54 AM
~/.bashrc doesn't work Kristian2 Slackware 6 05-19-2004 04:12 AM
bash's source code ramu_ak Linux - General 2 02-16-2003 06:06 PM
bash's source code ramu_ak Linux - General 0 02-16-2003 08:32 AM

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

All times are GMT -5. The time now is 10:24 PM.

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