2

I have the following for loop:

for f in ~/.lo-rcs/common/*
do
   . $f
done

which is returning this error:

bash: /home/sk/.lo-rcs/common/*: No such file or directory

I keep classifying my bashrc commands into multiple separate files and keeping them under $HOME/.lo-rcs/common. I want all the files to be sourced into Bash automatically, but it keeps throwing the "no such file..." error.

Question

Why isn't Bash searching for files with the same name as the globbing pattern string?

  • NOTE #1: .lo-rcs/common is my local rc configuration folder that contains separate files for aliases, one for export variables, one for functions etc. for ease of maintenance.
  • NOTE #2: All the files under .lo-rcs/common are hidden files, aka. files that are preceded by a dot.
0

1 Answer 1

6

~/.lo-rcs/common/* matches all the non-hidden files in that directory, if there are no files in that directory or all of them are hidden, the pattern evaluates to itself resulting to your error message.

There is no good reason to make those files hidden. - Just rename them and everything works as expected.

If you really want those files to be hidden, than you could use ~/.lo-rcs/common/.*. But be aware that this includes . and ...

1
  • 4
    FWIW: bash has a small menagerie of options that influence this behaviour: nullglob, failglob, dotglob, nocaseglob, and the environment variable GLOBIGNORE.
    – lcd047
    Jun 7, 2015 at 15:30

You must log in to answer this question.