bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suggestion for .bashrc


From: Matthew Persico
Subject: Re: Suggestion for .bashrc
Date: Tue, 4 Jan 2022 15:34:05 -0500

On Fri, Dec 31, 2021 at 10:33 AM Greg Wooledge <greg@wooledge.org> wrote:

> On Thu, Dec 30, 2021 at 08:46:16PM -0800, Kevin O'Gorman wrote:
> > So I propose extending  the stanza near the end of .bashrc:
> > if [ -f ~/.bash_aliases ]; then
> >     . ~/.bash_aliases
> > fi
>
> That code was written by your operating system vendor, or by your
> system administrator, or by you.  It's not something that comes from
> upstream bash.
>
> > by following it with
> > for __bash_alias in ~/.bash_aliases.d/* ; do
> >     if [ -f $__bash_alias ]; then
> >         source $__bash_alias
> >     fi
> > done
>
> 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
>
> Variable expansions need to be quoted inside [ but not inside [[.
>
>

-- 
Matthew O. Persico


reply via email to

[Prev in Thread] Current Thread [Next in Thread]