Am Tue, Jul 01, 2025 at 06:50:40PM -0500 schrieb Dale: > OK. I got one wrote, sort of. > […] > This is the script. Tell me what I did wrong. Please be kind. This is > the first real script I've ever done.
I’ll share some of my bash wisdom. Some may be nitpicks, others a matter of personal taste. > #/bin/bash > > > # Define the mount point > MOUNT_POINT="/home/dale/Desktop/Crypt" > LVM_DEV="/dev/vg.crypt/crypt" > > lsblk -o NAME -o LABEL | grep ^crypt-open > /dev/null -------------------------------------------^^^^^^^^^^^^ grep has a -q option to suppress output, no redirection necessary. > > if [ "$?" -eq "0" ] ; then The `if $?` part is actually kinda nicely readable, but you could of course also do a direct `if lsblk | grep; then`. > echo "Crypt file system is open" > > else echo "Crypt is not open. Please enter passphrase." ------^^^^^^^^^ 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`. > cryptsetup open $LVM_DEV crypt > fi > > # Check if the disk is already mounted > if mountpoint -q "$MOUNT_POINT"; then > echo "The disk is already mounted at $MOUNT_POINT." > # mount if not mounted > else mount $MOUNT_POINT > exit 0 > fi Same thing here with the `else` indentation. It is not visible on first sight that there is an if/else/fi structure here. And it’s not immediately clear that the exit also belongs into the else block. > This is simple still but hey, I'm new at this. It does work on one part > of it at least. ROFL Tool tip: shellcheck. It will give all sorts of feedback on common pitfalls and give suggestions on improvements. For instance, it showed me something I overlooked (you wrote #/bin/bash instead of #!/bin/bash). -- Grüße | Greetings | Salut | Qapla’ Please do not share anything from, with or about me on any social network. Electronically yours
signature.asc
Description: PGP signature