On 7/1/25 8:47 PM, Dale wrote:

>> Lol, it never occured to me that `else` may be followed by a command without 
>> semicolon, because I’ve always written it on its own line. It is however 
>> common practice to put the else on the same level of indentation as its 
>> respective `if` and `fi`.
> 
> Well, this part of the script may not have been executed yet.  Keep in
> mind, the device is open and mounted so it only runs the first bit, I
> guess it ignores the rest.  I may be wrong tho.  Does it need to be on
> its own line?  I'm learning, trying to anyway.  May as well learn it
> right.  LOL 


"else" doesn't need to be on its own line but people almost universally
do so because it makes it easier to read.



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".


-- 
Eli Schwartz

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to