Some suggestions:
#!/usr/bin/env bash
is a more portable shebang line.function prepare_volumes_for_exit()
can be simplified toprepare_volumes_for_exit()
.- Using
sudo
within a script is generally discouraged, since it makes it easy to do really bad things without explicit user consent. Instead, remove thesudo
s and tell the user to run the whole script as root. format_string
is an anti-pattern. First, because quotes are actually valid characters in paths, but more importantly because it is a strong indication that you're expecting the user to wrongly input broken strings.! [ $# -eq 2 ]
can be simplified as[ $# -ne 2 ]
.-
can be improved aswhile read -r drive_number volume_location vc_mapper mount_location … done <<< $(veracrypt -t -l)
This way, no word splitting happens on the input, and commands within thewhile read -r -u9 drive_number volume_location vc_mapper mount_location … done 9< <(veracrypt -t -l)
while
loop which happen to read from stdin won't break the loop. exit 0
is redundant.- By convention, scripts should be silent if there is nothing important to report, and any error messages should go to standard error rather than standard output.