On 2025-07-02, Eli Schwartz <eschwa...@gentoo.org> wrote:

> if [ "$?" -eq "0" ] ; then
>     echo "Crypt file system is open"
> else
>     echo "Crypt is not open.  Please enter passphrase."
>     cryptsetup open $LVM_DEV crypt
> fi
>
> This makes your eyes get drawn to the lines that are aligned left, which
> have the "when shall I run it?" logic. You can easily tell that
> "cryptsetup open" happens AFTER the "else".

Maybe it's just me, but I've switched from using [ ] to [[ ]].  I find
it works right the first try way more often. It's a bash built-in, and
the quoting and whitespace handling seems to work more like my brain
expects.  After decades of using [ ], I was still regularly tripped up
in ways that I don't seem to be using [[ ]].  [And it's even support
by busybox's ash shell.]

https://mywiki.wooledge.org/BashFAQ/031

https://stackoverflow.com/questions/3427872/whats-the-difference-between-and-in-bash



Reply via email to