From 4535f8f571c5435db0bc7fc4df2282dbb06aceeb Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Mon, 9 Apr 2018 21:43:16 -0400 Subject: [PATCH] rss functions switched from echo to printf --- burrow | 77 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/burrow b/burrow index 68c9727..1ed2be5 100755 --- a/burrow +++ b/burrow @@ -154,17 +154,17 @@ function parse_input { "update-git") arg_update_git=1 ;; "update-burrow") arg_update_burrow=1 ;; "rss") arg_rss=1 ;; - *) echo "Unknown command: $arg";; + *) printf "Unknown command: %s\n" "$arg";; esac done } function day_suffix { case $(date +%d) in - 01|1|21|31) echo "st";; - 02|2|22) echo "nd";; - 03|3|23) echo "rd";; - *) echo "th";; + 01|1|21|31) printf "st";; + 02|2|22) printf "nd";; + 03|3|23) printf "rd";; + *) printf "th";; esac } @@ -191,9 +191,9 @@ function die { # output message to stdout or stderr based on code if [[ ! -z "$msg" ]]; then if [[ "$code" == 0 ]]; then - echo "$msg" + printf "%s\n" "$msg" else - echo "$msg" >&2 + printf "%s\n" "$msg" >&2 fi fi exit "$code" @@ -250,18 +250,36 @@ function make_post_gophermap { if $use_gophermap; then if $use_date; then # if using gophermap and date - echo -e "1$(date +%Y-%m-%d) - $title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap" + printf "1%s - %s\t%s\t%s\t%s\n" \ + "$(date +%Y-%m-%d)" \ + "$title" \ + "$post_file_path" \ + "$config_gopher_server" \ + "$config_gopher_port" > "$temp_gophermap" else # if using gophermap but not date - echo -e "1$title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap" + printf "1%s\t%s\t%s\t%s\n" \ + "$title" \ + "$post_file_path" \ + "$config_gopher_server" \ + "$config_gopher_port" > "$temp_gophermap" fi else if $use_date; then # if not using gophermap but using date - echo -e "0$(date +%Y-%m-%d) - $title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap" + printf "0%s - %s\t%s\t%s\t%s\n" \ + "$(date +%Y-%m-%d)" \ + "$title" \ + "$post_file_path" \ + "$config_gopher_server" \ + "$config_gopher_port" > "$temp_gophermap" else # if not using gophermap or date - echo -e "0$title\t${post_file_path}\t${config_gopher_server}\t${config_gopher_port}" > "$temp_gophermap" + printf "0%s\t%s\t%s\t%s\n" \ + "$title" \ + "$post_file_path" \ + "$config_gopher_server" \ + "$config_gopher_port" > "$temp_gophermap" fi fi @@ -317,14 +335,11 @@ function make_post_temp { cat "${post_dir}/.template" > "$temp_post" else { - echo "----------------------------------------" - echo "$title" + printf "----------------------------------------\n%s\n" "$title" if $use_date; then date +"%B %d$(day_suffix), %Y" fi - echo "----------------------------------------" - echo "" - echo "" + printf "----------------------------------------\n\n\n" } > "$temp_post" fi @@ -350,7 +365,7 @@ function make_post_paths { type_gophermap="${config_dir_gopher}${post_type}/gophermap" if $use_gophermap; then - title_slug=$(echo "${title}" | \ + title_slug=$(printf "%s" "$title" | \ sed -E -e 's/[^[:alnum:]]/-/g' -e 's/^-+|-+$//g' | tr -s '-' | tr '[:upper:]' '[:lower:]') if $use_date; then post_dir="${config_dir_gopher}${post_type}/$(date +%Y%m%d)-$title_slug" @@ -364,7 +379,7 @@ function make_post_paths { else post_dir="${config_dir_gopher}${post_type}" post_path="${config_gopher_root}${post_type}" - title_slug=$(echo "${title}" | \ + title_slug=$(printf "%s" "$title" | \ sed -E -e 's/[^[:alnum:]]/-/g' -e 's/^-+|-+$//g' | tr -s '-' | tr '[:upper:]' '[:lower:]') if $use_date; then title_slug="$(date +%Y%m%d)-${title_slug}" @@ -428,10 +443,10 @@ function make_rss { head -n "${config_rss_num_entries}") { - echo "" - echo "${config_gopher_name}" - echo "gopher://${config_gopher_server}${config_gopher_root}" - echo "${config_gopher_desc}" + printf "\n" + printf "%s\n" "$config_gopher_name" + printf "gopher://%s%s/\n" "$config_gopher_server" "$config_gopher_root" + printf "%s\n" "$config_gopher_desc" } > "${config_dir_gopher}${config_file_rss}" for f in $search_list; do @@ -440,24 +455,24 @@ function make_rss { title="$(printf "%s" "$filename" | awk 'BEGIN { FS="-" } { $1=""; print $0; }' | sed "s|/gophermap||" | sed 's/^\ //' | sed 's/.*/\L&/; s/[a-z]*/\u&/g' )" { - echo "" - echo " ${title}" - echo " gopher://${config_gopher_server}/0${config_gopher_root}${config_dir_phlog}/${filename}" - echo " $(date -R --date="${date}")" - echo " " + printf "\n" + printf " %s\n" "$title" + printf " gopher://%s/0%s%s/%s\n" "$config_gopher_server" "$config_gopher_root" "$config_dir_phlog" "$filename" + printf " %s\n" "$(date -R --date="${date}")" + printf " \n" if grep -q "gophermap$" <<< $filename then awk -F"\t" '/^[2-9\+GITs].*\t/ {print $0; next} /^h.*\t/ { l=substr($1, 2, length($1)); print l "\n " substr($2, 5, length($2)); next } /^[0-1].*\t/ { l=substr($1, 2, length($1)); t=substr($1,1,1); print l "\n gopher://" $3 "/" t $2; next } {sub(/^i/, "", $1);print $1}' "$f" else cat "$f" fi - echo " ]]>" - echo "" + printf " ]]>\n" + printf "\n" } >> "${config_dir_gopher}${config_file_rss}" done - echo "" >> "${config_dir_gopher}${config_file_rss}" - echo "" >> "${config_dir_gopher}${config_file_rss}" + printf "\n" >> "${config_dir_gopher}${config_file_rss}" + printf "\n" >> "${config_dir_gopher}${config_file_rss}" } function edit_config {