On Tue, Jan 04, 2022 at 03:34:05PM -0500, Matthew Persico wrote: > On Fri, Dec 31, 2021 at 10:33 AM Greg Wooledge <g...@wooledge.org> wrote: > > You can edit the file yourself and make it work however you like. You > > have the right idea, but I'd write it like this: > > > > if [[ -d ~/.bash_aliases.d ]]; then > > for f in ~/.bash_aliases.d/*; do > > > > Doesn't that shell expansion in the 'for' loop need to be protected somehow > so that if there are no files in the directory, the loop does not try to > process literally the file '*' in that directory? > > [[ -f $f ]] && source "$f" > > done > > fi
That's precisely what the [[ -f $f ]] check is for. You could use -e instead of -f if you prefer, just in case you ever want it to be able to source named pipes or something.