From 2b24132f3cdaa01c3dc3dad22c6542dac52f7437 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 10 Jan 2016 23:17:48 +0100 Subject: [PATCH] Consistent use of [[ and (( instead of [ Another minor code cleanup. Within [[ ... ]] and (( ... )) (but not [ ... ]) there is a different shell parsing context in which field splitting (a.k.a. word splitting) and pathname expansion (a.k.a. filename globbing) don't apply, so consistently use '[[' (and '((' for arithmetics) instead of '[' and remove unnecessary quotes. Since '[[ x == y]]' does 'case'-like glob pattern matching on 'y', the quotes to the right of '==' need to be kept for variables or glob characters, except if a glob pattern is wanted. --- bb.sh | 220 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 111 insertions(+), 109 deletions(-) diff --git a/bb.sh b/bb.sh index 147cd20..3cc5656 100755 --- a/bb.sh +++ b/bb.sh @@ -149,10 +149,10 @@ global_variables() { # Check for the validity of some variables # DO NOT EDIT THIS FUNCTION unless you know what you're doing global_variables_check() { - [[ "$header_file" == ".header.html" ]] && + [[ $header_file == .header.html ]] && echo "Please check your configuration. '.header.html' is not a valid value for the setting 'header_file'" && exit - [[ "$footer_file" == ".footer.html" ]] && + [[ $footer_file == .footer.html ]] && echo "Please check your configuration. '.footer.html' is not a valid value for the setting 'footer_file'" && exit } @@ -160,17 +160,17 @@ global_variables_check() { # Test if the markdown script is working correctly test_markdown() { - [[ -z "$markdown_bin" ]] && return 1 - [[ -z "$(which diff)" ]] && return 1 + [[ -z $markdown_bin ]] && return 1 + [[ -z $(which diff) ]] && return 1 - in="/tmp/md-in-${RANDOM}.md" - out="/tmp/md-out-${RANDOM}.html" - good="/tmp/md-good-${RANDOM}.html" + in=/tmp/md-in-${RANDOM}.md + out=/tmp/md-out-${RANDOM}.html + good=/tmp/md-good-${RANDOM}.html echo -e "line 1\n\nline 2" > "$in" echo -e "

line 1

\n\n

line 2

" > "$good" $markdown_bin $in > $out 2> /dev/null diff $good $out &> /dev/null # output is irrelevant, we'll check $? - if [[ $? -ne 0 ]]; then + if (($? != 0)); then rm -f "$in" "$good" "$out" return 1 fi @@ -183,7 +183,7 @@ test_markdown() { # Parse a Markdown file into HTML and return the generated file markdown() { out=$(echo $1 | sed 's/md$/html/g') - while [ -f "$out" ]; do out=$(echo $out | sed 's/\.html$/\.'$RANDOM'\.html/'); done + while [[ -f $out ]]; do out=$(echo $out | sed 's/\.html$/\.'$RANDOM'\.html/'); done $markdown_bin "$1" > "$out" echo "$out" } @@ -191,9 +191,9 @@ markdown() { # Prints the required google analytics code google_analytics() { - [[ -z "$global_analytics" ]] && [[ -z "$global_analytics_file" ]] && return + [[ -z $global_analytics && -z $global_analytics_file ]] && return - if [[ -z "$global_analytics_file" ]]; then + if [[ -z $global_analytics_file ]]; then echo "