LinuxQuestions.org
Review your favorite Linux distribution.
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 04-03-2010, 05:49 AM   #16
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195

Quote:
Originally Posted by forusword View Post
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

could it be the lack of a line break in the first line here and the use of whitespace in the second line?
I don't think so; if [ -f /etc/bashrc ]; then is valid and there is a space after the "." so that's OK.
 
Old 04-03-2010, 06:19 PM   #17
kakaka
Member
 
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
dot space equals source

Exactly. In fact, to illustrate, please consider this little session:


Code:
> echo $SHELL
/bin/bash
> ps
  PID TTY          TIME CMD
 6420 pts/7    00:00:00 bash
10118 pts/7    00:00:00 ps
> # So, I'm using bash as my shell.
> cat not_fubar.sh
echo 'Not Fubar'
>.  not_fubar.sh
Not Fubar
> source not_fubar.sh
Not Fubar
> .not_fubar.sh
If '.not_fubar.sh' is not a typo you can use command-not-found to lookup the package that contains it, like this:
    cnf .not_fubar.sh
>
In bash, a dot followed by a space is the same as the source command.
In fact, if I substitute the trivial shell script for /etc/bashrc, but
take the rest of the code, character for character, spaces and all,
right out the post, it works just fine:

Code:
> if [ -f not_fubar.sh ]; then
> . not_fubar.sh
> fi
Not Fubar
>
In fact, there are two spaces after the dot in the fifth command sequence, and it works just fine. I can place several spaces before
and after the dot:

Code:
>   .  not_fubar.sh
Not Fubar
>
and it still works just fine. Space is not much of an issue, except for NASA.

OH, and as far as the comment about not having to edit quite so many files to change aliases, etc., yes, some distros, such as the one I use, source a file with a name like .alias or some such from the .bashrc, so they are all in one place.


Now back to your regularly scheduled programming issue.

I have a $HOME/log directory for a variety of purposes. For example, whenever I think there's an issue with files being executed/sourced when the shell starts, such as sourcing .bash_profile, I'll add a line to the files like:

Code:
echo ".bash_profile being run @ `date`"  >>  $HOME/log/login.log
I'll add the appropriate version of that line to my .bashrc:

Code:
echo ".bashrc being run @ `date`"  >>  $HOME/log/login.log
and if I have access to /etc/bashrc or if it's being sourced from .bash_profile then I can also log when it's being sourced by the .bash_profile. In one older version of a distro I use, there was a bug in the distro, /etc/profile was actually being executed twice. I tracked it down using this method, and set up a workaround.

Hope this helps.
 
1 members found this post helpful.
  


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
.bash_profile dimi Linux - General 1 08-23-2005 09:00 PM
.bash_profile sikandar Linux - Software 9 08-31-2003 11:01 AM
Finding Module Dependencies...(Still loading...still loading..still loading..HANG!!!) Aeudian Linux - General 3 08-11-2003 04:31 PM
Finding Module Dependencies.....(still loading....Still loading....still loading) Aeudian Linux - Newbie 1 07-28-2003 03:27 PM
.bash_profile Wasim Haider Linux - General 2 09-16-2002 08:12 AM


All times are GMT -5. The time now is 08:31 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration