rsync-time-backup icon indicating copy to clipboard operation
rsync-time-backup copied to clipboard

ShellCheck indicates some issues

Open NoNoNo opened this issue 6 years ago • 1 comments

ShellCheck, a static analysis tool for shell scripts, indicates some issues:

$ shellcheck rsync_tmbackup.sh

In rsync_tmbackup.sh line 3:
APPNAME=$(basename $0 | sed "s/\.sh$//")
                   ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 35:
        echo "Usage: $(basename $0) [OPTION]... <SOURCE> <[USER@HOST:]DESTINATION> [exclude-pattern-file]"
                                ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 63:
        fn_run_cmd "find "$DEST_FOLDER" -maxdepth 1 -type d -name "????-??-??-??????" -prune | sort -r"
                          ^-- SC2027: The surrounding quotes actually unquote this. Remove or escape them.
                          ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 79:
        if [[ "$DEST_FOLDER" =~ ^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$ ]]
                                                 ^-- SC1001: This \- will be a regular '-' in this context.
                                                                 ^-- SC1001: This \- will be a regular '-' in this context.
                                                                     ^-- SC1001: This \: will be a regular ':' in this context.

In rsync_tmbackup.sh line 94:
                eval $1
                     ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 157:
                        echo $RSYNC_FLAGS
                             ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 273:
                RUNNINGCMD="$(procps -wwfo cmd -p $RUNNINGPID --no-headers | grep "$APPNAME")"
                                                  ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 341:
                TIMESTAMP=$(fn_parse_date $BACKUP_DATE)
                                          ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 349:
                if   [ $TIMESTAMP -ge $KEEP_ALL_DATE ]; then
                       ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 351:
                elif [ $TIMESTAMP -ge $KEEP_DAILIES_DATE ]; then
                       ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 390:
        eval $CMD
             ^-- SC2086: Double quote to prevent globbing and word splitting.

In rsync_tmbackup.sh line 417:
        if [ -n "$(grep "rsync error:" "$LOG_FILE")" ]; then
             ^-- SC2143: Use grep -q instead of comparing output with [ -n .. ].

In rsync_tmbackup.sh line 419:
        elif [ -n "$(grep "rsync:" "$LOG_FILE")" ]; then
               ^-- SC2143: Use grep -q instead of comparing output with [ -n .. ].

NoNoNo avatar Sep 12 '17 19:09 NoNoNo

Thanks, I'm leaving this open for now. Ideally we should have unit tests first, so that we can run this kind of analysis tool and safely refactor the code.

laurent22 avatar Sep 21 '17 10:09 laurent22