[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Setting two variables based on condition
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: Setting two variables based on condition |
Date: |
Thu, 8 Apr 2021 08:53:49 +0200 |
On Thu, Apr 08, 2021 at 08:11:33AM +0200, michael-franzese@gmx.com wrote:
> Is this the way to set two variables "at" and "gf" when condition is true.
>
> [[ "$dsattr" == "attrib" ]] && at="$gf" && gf=""
>
>
No, if the assignment to at fails (it may be readonly), then gf would
not be assigned either. Don't try to be smart, just do
if [[ ... ]]; then
assignments here
fi
i.e.
if [[ $dsattr == attrib ]]; then
at=$gf
gf=
fi
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
.