[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
condition to execute
From: |
lisa-asket |
Subject: |
condition to execute |
Date: |
Tue, 6 Jul 2021 05:00:03 +0200 (CEST) |
> 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
- condition to execute, lisa-asket, 2021/07/05
- Re: condition to execute, Lawrence Velázquez, 2021/07/05
- condition to execute,
lisa-asket <=
- Re: condition to execute, David, 2021/07/05
- condition to execute, lisa-asket, 2021/07/05
- Re: condition to execute, Greg Wooledge, 2021/07/06
- condition to execute, lisa-asket, 2021/07/06
- Re: condition to execute, Lawrence Velázquez, 2021/07/06
- condition to execute, lisa-asket, 2021/07/06
- Re: condition to execute, Lawrence Velázquez, 2021/07/06
- Re: condition to execute, Eli Schwartz, 2021/07/06
- Re: condition to execute, Greg Wooledge, 2021/07/06
- condition to execute, lisa-asket, 2021/07/06