Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The script is nicely written. I only have minor suggestions that are barely more than nitpicks.

Function declaration style

Instead of this:

function scheme {

The generally preferred style generally preferred style for declaring functions is this:

scheme() {

Redundant local variable

The local variable token is redundant here:

function scheme {
 local token="$@"
 echo "hourly ${token}"
}

You could simplify to:

echo "hourly $@"

Simplify condition

This condition can be simplified:

if (( ${#backups[@]} > 0 )); then
 latest_backup="${backups[0]}"
else
 latest_backup=""
fi

To just this:

latest_backup="${backups[0]}"

Instead of this:

if [[ "${password_file}" != "" ]]; then

You can omit the != "":

if [[ "${password_file}" ]]; then

Don't repeat yourself

The echo statement is duplicated for the sake of underlining:

echo "Backing up ${source_directory}"
echo "Backing up ${source_directory}" | sed "s/./=/g"

It would be good to create a helper function for this purpose:

print_heading() {
 echo "$@"
 echo "$@" | sed "s/./=/g"
}

The script is nicely written. I only have minor suggestions that are barely more than nitpicks.

Function declaration style

Instead of this:

function scheme {

The generally preferred style for declaring functions is this:

scheme() {

Redundant local variable

The local variable token is redundant here:

function scheme {
 local token="$@"
 echo "hourly ${token}"
}

You could simplify to:

echo "hourly $@"

Simplify condition

This condition can be simplified:

if (( ${#backups[@]} > 0 )); then
 latest_backup="${backups[0]}"
else
 latest_backup=""
fi

To just this:

latest_backup="${backups[0]}"

Instead of this:

if [[ "${password_file}" != "" ]]; then

You can omit the != "":

if [[ "${password_file}" ]]; then

Don't repeat yourself

The echo statement is duplicated for the sake of underlining:

echo "Backing up ${source_directory}"
echo "Backing up ${source_directory}" | sed "s/./=/g"

It would be good to create a helper function for this purpose:

print_heading() {
 echo "$@"
 echo "$@" | sed "s/./=/g"
}

The script is nicely written. I only have minor suggestions that are barely more than nitpicks.

Function declaration style

Instead of this:

function scheme {

The generally preferred style for declaring functions is this:

scheme() {

Redundant local variable

The local variable token is redundant here:

function scheme {
 local token="$@"
 echo "hourly ${token}"
}

You could simplify to:

echo "hourly $@"

Simplify condition

This condition can be simplified:

if (( ${#backups[@]} > 0 )); then
 latest_backup="${backups[0]}"
else
 latest_backup=""
fi

To just this:

latest_backup="${backups[0]}"

Instead of this:

if [[ "${password_file}" != "" ]]; then

You can omit the != "":

if [[ "${password_file}" ]]; then

Don't repeat yourself

The echo statement is duplicated for the sake of underlining:

echo "Backing up ${source_directory}"
echo "Backing up ${source_directory}" | sed "s/./=/g"

It would be good to create a helper function for this purpose:

print_heading() {
 echo "$@"
 echo "$@" | sed "s/./=/g"
}
Source Link
janos
  • 112.9k
  • 15
  • 154
  • 396

The script is nicely written. I only have minor suggestions that are barely more than nitpicks.

Function declaration style

Instead of this:

function scheme {

The generally preferred style for declaring functions is this:

scheme() {

Redundant local variable

The local variable token is redundant here:

function scheme {
 local token="$@"
 echo "hourly ${token}"
}

You could simplify to:

echo "hourly $@"

Simplify condition

This condition can be simplified:

if (( ${#backups[@]} > 0 )); then
 latest_backup="${backups[0]}"
else
 latest_backup=""
fi

To just this:

latest_backup="${backups[0]}"

Instead of this:

if [[ "${password_file}" != "" ]]; then

You can omit the != "":

if [[ "${password_file}" ]]; then

Don't repeat yourself

The echo statement is duplicated for the sake of underlining:

echo "Backing up ${source_directory}"
echo "Backing up ${source_directory}" | sed "s/./=/g"

It would be good to create a helper function for this purpose:

print_heading() {
 echo "$@"
 echo "$@" | sed "s/./=/g"
}
lang-bash

AltStyle によって変換されたページ (->オリジナル) /