From 371797ee9ee5e91d23a11ea1fcde114d90059184 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sat, 1 Oct 2016 07:18:59 -0500 Subject: [PATCH] Use printf --- backup | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/backup b/backup index d962a6a..d1a70ed 100755 --- a/backup +++ b/backup @@ -20,7 +20,7 @@ declare -r description="latest incremental backup" set -e if [[ $EUID -ne 0 ]]; then - echo "Script must be run as root." + printf "Script must be run as root.\n" exit fi @@ -43,13 +43,13 @@ for x in $UUIDS; do UUIDS_ARRAY[$i]=$x i=$((i+1)) done -echo "Selected a mounted BTRFS device to backup to." +printf "Selected a mounted BTRFS device to backup to.\n" disk=-1 while [[ $disk -lt 0 || $disk -gt $i ]]; do for x in "${!TARGETS_ARRAY[@]}"; do - echo -e "$((x+1))) ${UUIDS_ARRAY[$x]}\t(${TARGETS_ARRAY[$x]})" + printf "%s) %s (%s)\n" "$((x+1))" "${UUIDS_ARRAY[$x]}" "${TARGETS_ARRAY[$x]}" done - echo "0) Exit" + printf "0) Exit\n" read -r -p "Enter a number: " disk done if [[ $disk == 0 ]]; then @@ -57,12 +57,12 @@ if [[ $disk == 0 ]]; then fi selected_uuid="${UUIDS_ARRAY[$((disk-1))]}" selected_mnt="${TARGETS_ARRAY[$((disk-1))]}" -echo "You selected the disk with UUID $selected_uuid." +printf "You selected the disk with UUID %s.\n" "$selected_uuid" if [[ -f /etc/conf.d/snapper ]]; then source /etc/conf.d/snapper else - echo "ERROR: /etc/conf.d/snapper does not exist!" + printf "ERROR: /etc/conf.d/snapper does not exist!\n" exit 1 fi @@ -70,22 +70,22 @@ for x in $SNAPPER_CONFIGS; do source /etc/snapper/configs/$x - echo "At '$x' configuration" + printf "At '%s' configuration\n" "$x" old_number=$(snapper -c "$x" list -t single | awk '/'"$selected_uuid"'/ {print $1}') old_snapshot=$SUBVOLUME/.snapshots/$old_number/snapshot if [[ -z "$old_number" ]]; then - echo "No backups have been performed for '$x' on this disk." + printf "No backups have been performed for '%s' on this disk.\n" "$x" read -r -p "Enter name of directory to store backups: " mybackupdir - echo "This will be the initial backup for snapper configuration '$x' to this disk. This could take awhile." + printf "This will be the initial backup for snapper configuration '%s' to this disk. This could take awhile.\n" "$x" BACKUPDIR="$selected_mnt/$mybackupdir" mkdir -p "$BACKUPDIR" else - mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'$selected_uuid'/ {print $5}' | awk -F "," '{print $1}' | awk -F"=" '{print $2}') + mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'"$selected_uuid"'/ {print $5}' | awk -F "," '{print $1}' | awk -F"=" '{print $2}') BACKUPDIR="$selected_mnt/$mybackupdir" if [[ ! -d $BACKUPDIR ]]; then - echo "ERROR: $BACKUPDIR is not a directory on $selected_uuid." + printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid" exit 1 fi fi @@ -95,10 +95,10 @@ for x in $SNAPPER_CONFIGS; do new_info=$SUBVOLUME/.snapshots/$new_number/info.xml sync backup_location=$BACKUPDIR/$x/$new_number/ - echo "Backup location: $backup_location" + printf "Backup location: %s\n" "$backup_location" read -r -n 1 -p "Continue (y/n)? " cont_backup - echo + printf "\n" if [[ "$cont_backup" != "y" ]]; then continue fi @@ -130,4 +130,4 @@ done date > "$HOME"/.lastbackup -echo "Done!" +printf "Done!\n"