shell-scripts: Use [[ instead of [ where possible

Replace all occurrences of [ with [[ in bash and zsh scripts and
configs.
Performance wise it makes sense to use the builtin instead of calling an
external command also when from a functionality stand point `test` would
suffice.
This commit is contained in:
2020-10-03 01:29:29 +02:00
parent 29d28a25ee
commit 4cb445c2b5
14 changed files with 64 additions and 64 deletions

View File

@@ -8,9 +8,9 @@
## format of zshs extended history.
## An automatic backup is created before deleting that can be used for recovery.
[ $# -eq 1 ] || { echo "Specify history file" >&2; exit 1; }
[ -e "$1" ] || { echo "File does not exist" >&2; exit 1; }
[ "$(stat -c '%a' "$1")" = "600" ] || { echo "File does not look like a history file" >&2; exit 1; }
[[ $# -eq 1 ]] || { echo "Specify history file" >&2; exit 1; }
[[ -e "$1" ]] || { echo "File does not exist" >&2; exit 1; }
[[ "$(stat -c '%a' "$1")" = "600" ]] || { echo "File does not look like a history file" >&2; exit 1; }
# Sort the commands per number of occurrences
most_used="$(\
@@ -42,11 +42,11 @@ else
echo
fi
[ "${#commands}" -gt 0 ] || exit 0
[[ "${#commands}" -gt 0 ]] || exit 0
printf '%s\n' "${commands[@]}" | column -x
echo "Please confirm the deletion of these commands in $1 ('yes')"
read yn
[ "$yn" = "yes" ] || exit 1
[[ "$yn" = "yes" ]] || exit 1
tempd="$(mktemp -d)"
cp "$1" "$tempd/$(basename "$1")"