> From: Lawrence Velázquez <vq@larryv.me>
> To: lisa-asket@perso.be
> Subject: Re: condition to execute
> Date: 05/07/2021 06:43:40 Europe/Paris
> Cc: help-bash@gnu.org
> On Mon, Jul 5, 2021, at 12:03 AM, lisa-asket@perso.be wrote:
> > Would the following be good to source my .bashrc when the value
> >
> > of the variable f is 1?
> >
> >
> >
> > Â (( $f == 1 )) && source ${HOME}/.bashrc
> You don't have to use '$' to reference variables in arithmetic
> contexts. (I am going to assume, perhaps unwisely, that f takes
> on known safe values and doesn't require validation.) Additionally,
> expanding parameters outside of double quotes is very often a bug
> (although $HOME is unlikely to cause you problems). It's easily
> addressed by adding double quotes or using ~ instead.
> (( f == 1 )) && source ~/.bashrc
> A relatively minor consideration is that this list has a nonzero
> exit status if f != 1. This suggests failure, even if it is not
> actually a failure condition. (It's impossible to judge, given the
> utter lack of context.) Many people would not care about this, and
> perhaps you don't either, but if f != 1 is not actually a failure
> condition, then using 'if' avoids implying that it is.
What do you mean by a failure? If `f` is `0`, then `source` is not executed.
That's about it.
> if (( f == 1 )); then source ~/.bashrc; fi
--
vq