LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-22-2010, 09:48 AM   #1
brian.hussey
LQ Newbie
 
Registered: Aug 2008
Distribution: Fedora
Posts: 5

Rep: Reputation: 0
Bash scripting issue with "source" or . (dot) operator (Cygwin & Ubuntu)


Hi All,
This one is driving me crazy.

My .bashrc is set as:
if [ -d ~/.bashrc.d ]; then
for file in $(/bin/ls ~/.bashrc.d/); do
. '~/.bashrc.d/'$file
done
fi

So in theory any files located in the ~/.bashrc.d/ directory will automatically get loaded.
great!

The problem is that when running the script, the file (that it has already found) that it tries to load gives an error like:

bash: ~/.bashrc.d/aliases: No such file or directory

I've debugged and debugged but the best I've come up with is the line doing the source (the . ) is:
. ~/.bashrc.d/aliases
(the file does exist btw)

if I run the same command from the shell it works fine and all my aliases load correctly.

Can anyone help me please?

I'm getting this in Cygwin and Ubuntu.

Thanks,
Brian
 
Old 01-22-2010, 10:28 AM   #2
brian.hussey
LQ Newbie
 
Registered: Aug 2008
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
Hi All,
I figured it out:
. '~/.bashrc.d/'$file
should have been:
. ~/.bashrc.d/$file

Then it all works correctly.

I hope this helps someone, someday.

Brian
 
Old 01-22-2010, 10:49 AM   #3
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
You are doing two things wrong here:
1. Trying to do anything besides display the output of "ls"
2. Using single-quotes instead of double-quotes
Code:
shopt -s nullglob
for file in "$HOME/.bashrc.d"/*; do
   source "$file"
done
shopt -u nullglob
 
Old 01-22-2010, 02:11 PM   #4
brian.hussey
LQ Newbie
 
Registered: Aug 2008
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks very much!
 
  


Reply

Tags
bash, bashrc


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
1st script attempt; cygwin; fails "bash: myscript : command not found" engineerd1 Linux - Newbie 8 11-08-2009 05:03 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
shell scripting: "formatting" issue with text files eur0dad Programming 3 08-17-2006 11:50 AM
Bash scripting and && operator Dark_Helmet Programming 16 09-18-2005 10:57 PM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 03:07 AM


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