I don't think you will be able to guarantee that.
So, let's assume you have a command that takes the password in a prompt, eg.
echo mypassword | cryptsetup luksOpen /dev/disk volume`
And want to ask for the password once and open several volumes:
#!/bin/sh
set -e
read -p "What's the password? " password || exit 1
for disk in disk1 disk2 disk3; do
FOLDER=/media/$USER/$disk
echo "$password" | cryptsetup luksOpen /dev/$disk $disk && \
mkdir -p "$FOLDER" && \
mount /dev/mapper/$disk "$FOLDER/$disk"
done
password="xxxxxxxxxxxxxxxxxxxxxx"
This shell script would do. Except that, after bash finishes, and the memory is returned to the system, we have no guarantee that the password itself is not still in memory somewhere (no, despite that last statement your shell may not overwrite the location where it was saved).
So, we could rewrite this in C, and manually ensure that such location is overwriten, using something like memset_s
(yes, a normal memset wouldn't do).
Still, there could be copies of the plaintext password in the stdio buffers, the ones used by cryptsetup, etc. The kernel will not give such pages to other programs without first zeroing them, but if a forensic investigator came freezing your memory slots with nitrogen and dumping it contents, it could still be there.
Moreover, the actual disk key (decrypted from the passphrase) will be in memory, for as long as you have the volumes mounted. So, it is probably not worth insisting on ensuring that much, and just letting the program finish would be acceptable.
I would suggest encrypting the main disk partition (and swap, of course), and have keyfiles for each of the other disks on there (they can be readable just for root). Thus, you only need to enter one password (at boot time) and will be able to decrypt all disks. There are no encrypted passwords laying out when the system is powered down, and if an attacker got root your system so they would be able to steal your keyfiles, he could access the files directly as well (and do too many other nasty things), so it doesn't make things much more insecure.
The main scenario for that I can think is where repeated access is obtained, eg. your encrypted disks are cloned, and later (after you shreded some secrets from them), they obtain your passphrase/keyfiles, thus being able to decrypt their earlier copy. They could probably do that as well by extracting the in-memory disk keys, but the existence of the keyfiles make things simpler. (In order to avoid this, change your passwords and keyfiles and rekey the disk after removing the Coke secret formula)
Hope this helps