From ba012c436e582bbb59f1749cb44d67b781f82cbd Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 11 Jan 2016 00:16:50 +0100 Subject: [PATCH] More correct and effective use of arrays --- bb.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bb.sh b/bb.sh index 3cc5656..a53ce6d 100755 --- a/bb.sh +++ b/bb.sh @@ -392,7 +392,7 @@ is_boilerplate_file() { ( "$index_file" | "$archive_index" | "$tags_index" | "$footer_file" | "$header_file" | "$global_analytics_file" | "$prefix_tags"* ) return 0 ;; ( * ) # Check for excluded - for excl in ${html_exclude[*]}; do + for excl in "${html_exclude[@]}"; do [[ $name == "$excl" ]] && return 0 done return 1 ;; @@ -523,9 +523,9 @@ parse_file() { IFS=, read -r -a array <<< "$tags" echo -n "

$template_tags_line_header " >> "$content" - (for item in "${array[@]}"; do + for item in "${array[@]}"; do echo -n "$item, " - done ) | sed 's/, $/<\/p>/g' >> "$content" + done | sed 's/, $/<\/p>/g' >> "$content" else echo "$line" >> "$content" fi @@ -738,7 +738,7 @@ rebuild_index() { # Accepts either filename as first argument, or post content at stdin # Prints one line with space-separated tags to stdout tags_in_post() { - sed -n "/^

$template_tags_line_header/{s/^

$template_tags_line_header//;s/<[^>]*>//g;s/[ ,]\+/ /g;p;}" $1 | tr ', ' ' ' + sed -n "/^

$template_tags_line_header/{s/^

$template_tags_line_header//;s/<[^>]*>//g;s/[ ,]\+/ /g;p;}" "$1" | tr ', ' ' ' } # Finds all posts referenced in a number of tags. @@ -746,8 +746,9 @@ tags_in_post() { # Prints one line with space-separated tags to stdout posts_with_tags() { (($# < 1)) && return - tag_files=$(for i in "$@"; do echo -n $prefix_tags""$i.html" "; done) - sed -n '/^

/{s/.*href="\([^"]*\)">.*/\1/;p;}' $tag_files 2> /dev/null + set -- "${@/#/$prefix_tags}" + set -- "${@/%/.html}" + sed -n '/^

/{s/.*href="\([^"]*\)">.*/\1/;p;}' "$@" 2> /dev/null } # Rebuilds tag_*.html files @@ -880,9 +881,7 @@ create_includes() { echo '' >> ".header.html" echo '' >> ".header.html" echo '' >> ".header.html" - for css_file in ${css_include[*]}; do - echo '' >> ".header.html" - done + printf '\n' "${css_include[@]}" >> ".header.html" if [[ -z $global_feedburner ]]; then echo '' >> ".header.html" else