1

I've been working a bash script to automate the process of opening and closing an LVM over LUKS external hard drive. However I continue to receive errors on line 28:

$(vgchange -a n ; cryptsetup luksClose vol)

The error I receive:

$ sudo ./encryption.sh -l
Locking System..............
./encryption.sh: line 28: 0: command not found
System Locked!

Here is the rest of the code for reference:

if [ $1 = -u ] ; then
    $(cryptsetup luksOpen /dev/sdb2 vol)
    echo "Unlocking.................." | pv -qL 10
    $(mount /dev/mapper/vol-lvroot /mnt ; mount /dev/mapper/vol-lvvar /mnt/var ; mount /dev/mapper/vol-lvhome /mnt/home ; mount /dev/sdb1 /mnt/boot)
    echo "System Mounted!" | pv -qL 10
#   exit 0
fi

if [ $1 = -l ] ; then
    $(umount /mnt/var ; umount /mnt/home ; umount /mnt/boot ; umount /mnt/)
    echo "Locking System.............." | pv -qL 10
    $(vgchange -a n ; cryptsetup luksClose vol)
    echo "System Locked!" | pv -qL 10
    exit 0
fi

Other information:

  1. I receive no apparent error when running the command in question by itself interactively.

  2. I'm new to writing bash, so any recommendations and constructive criticism is appreciated.

  3. The process appears to complete successfully, but I don't understand the error or how to make them go away.

  4. Upon further research when running the troubled code alone in interactive mode it does provide output after being executed.

This is given after posting the troubled code interactively.

0 logical volume(s) in volume group "vol" now active
2

By putting commands inside a $( .. ) block you're doing command substitution. That means that the commands inside that block is executed, and the output of those commands will be evaluated by bash as other commands to be executed. So if the command outputs the text

0 logical volume(s) in volume group "vol" now active

then the shell will try to run that as a command, and as it starts with 0 it looks for a command with that name.

Why are you putting the commands in $( .. ) block? What are you trying to achieve with that?

  • Like I said, I'm new to BASH, and was implementing the monkey-see monkey-do method without understanding what I was seeing. Thanks for the explanation. – Jay Holister Nov 13 '14 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.