From a4726decd7f08623291ffac6d85c1ce81bbd4b34 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 28 Dec 2010 22:22:11 -0500 Subject: [PATCH] s/echo/printf/ -- and some extra juju to go with --- aurcomm | 4 ++-- aurdiff | 4 ++-- ethstat | 4 ++-- flac2mp3 | 22 ++++++++++------------ git-all | 12 ++++++------ git-retrotag | 8 ++++---- hex2rgb | 8 ++++---- hglink | 18 +++++++++--------- list2html | 49 ++++++++++++++++++++++--------------------------- mancx | 4 ++-- pkgfile | 10 +++++----- pp | 10 +++++----- randomJunk | 4 ++-- sabs | 10 +++++----- simplentp | 6 +++--- vbox | 7 +------ volOSD | 2 +- walk | 8 ++++---- wgetzen | 2 +- xo | 2 +- 20 files changed, 91 insertions(+), 103 deletions(-) diff --git a/aurcomm b/aurcomm index f397f76..902dc18 100755 --- a/aurcomm +++ b/aurcomm @@ -37,7 +37,7 @@ getpkgID() { if ! (( $# )); then if [[ ! -f PKGBUILD ]]; then - echo "error: no PKGBUILD found and no arg provided" + printf "error: no PKGBUILD found and no arg provided\n" exit 1 fi eval $(grep '^pkgname=' PKGBUILD) @@ -46,7 +46,7 @@ fi pkgname=${1:-$pkgname} pkgID=$(getpkgID $pkgname) -[[ $pkgID ]] || { echo "error: package \`$pkgname' not found"; exit 1; } +[[ $pkgID ]] || { printf "error: package \`%s' not found" "$pkgname"; exit 1; } curl -s "$AURURL/packages.php?ID=$pkgID$showall" | commfilter diff --git a/aurdiff b/aurdiff index 7b6930d..16e4a8f 100755 --- a/aurdiff +++ b/aurdiff @@ -7,13 +7,13 @@ DIFF=${DIFF:-diff} if [[ ! -f PKGBUILD ]]; then - echo "error: No PKGBUILD found in working directory." + printf "error: No PKGBUILD found in working directory.\n" exit 1 fi >&2 eval $(grep '^pkgname=' PKGBUILD) if [[ -z $pkgname ]]; then - echo "error: pkgname not found in PKGBUILD" + printf "error: pkgname not found in PKGBUILD\n" exit 1 fi >&2 diff --git a/ethstat b/ethstat index 23ee779..7033666 100755 --- a/ethstat +++ b/ethstat @@ -1,6 +1,6 @@ #!/bin/bash -echo "Network Device Statistics (in mb)" +printf "Network Device Statistics (in mb)\n" printf "\n%8s%10s%10s%8s\n" "Device" "Sent" "Received" "Ratio" #echo --------------------------------------- for dev in /sys/class/net/*; do @@ -11,4 +11,4 @@ for dev in /sys/class/net/*; do ratio=$(posty <<< ":2 $sent $recv /") printf "%8s%10.2f%10.2f%8.2f\n" $dev $sent $recv $ratio done -echo + diff --git a/flac2mp3 b/flac2mp3 index 9cb042f..a68b8d5 100755 --- a/flac2mp3 +++ b/flac2mp3 @@ -30,21 +30,19 @@ die() { } >&2 mkdir_vp() { - mkdir -p "$1" && echo "$ARG0: created directory ``$1'" + mkdir -p "$1" && printf "%s: created directory \`%s'" "$ARG0" "$!" } usage() { - echo "usage: $ARG0 [options] SOURCE... DESTINATION" - echo " $ARG0 [options] -t DESTINATION SOURCE..." - echo - echo " -f overwrite existing files" - echo " -h display this help message" - echo " -l ARGS additional parameters to pass to lame" - echo " -q don't print to stdout" - echo " -r convert directories recursively (implies -p)" - echo " -t PATH use PATH as destination for converted SOURCEs" - echo " -w quit on warnings" - echo + printf "usage: $ARG0 [options] SOURCE... DESTINATION\n" + printf " $ARG0 [options] -t DESTINATION SOURCE...\n\n" + printf " -f overwrite existing files\n" + printf " -h display this help message\n" + printf " -l ARGS additional parameters to pass to lame\n" + printf " -q don't print to stdout\n" + printf " -r convert directories recursively (implies -p)\n" + printf " -t PATH use PATH as destination for converted SOURCEs\n" + printf " -w quit on warnings\n\n" } >&2 # find flac files in a given dir, recursing unless told otherwise diff --git a/git-all b/git-all index c64e6d4..52992b7 100755 --- a/git-all +++ b/git-all @@ -50,7 +50,7 @@ breadlink() { pwd -P ) else - echo "$path" + printf "%s\n" "$path" fi } do_all_action() { @@ -72,12 +72,12 @@ stat_repos() { local repo=$(breadlink ${repo%.git}) cd "$repo" - [[ -n $(git status -s | grep -v "^??") ]] && echo "$repo" + [[ -n $(git status -s | grep -v "^??") ]] && printf "%s\n" "$repo" done } job_summary() { - echo + printf "\n" msg "Job Summary For $count Repos: git $*" if [[ ${#fail[@]} -eq 0 ]]; then @@ -85,15 +85,15 @@ job_summary() { else for repo in "${fail[@]}"; do repofail "$repo" - (( VERBOSE )) && { sed 's/^/ /' <<< "${output[$repo]}"; echo; } >&2 + (( VERBOSE )) && { sed 's/^/ /' <<< "${output[$repo]}"; printf "\n"; } >&2 done fi - echo + printf "\n" for repo in "${pass[@]}"; do repopass "$repo" done - echo + printf "\n" } # sanity check diff --git a/git-retrotag b/git-retrotag index a025df1..15b443f 100755 --- a/git-retrotag +++ b/git-retrotag @@ -87,8 +87,8 @@ review_candidates() { ask_abort() { read -N1 -p "Satisfied? Continue with tagging? (y/N) " reply - echo - [[ ! "$reply" =~ [Yy] ]] && { echo "Aborting..."; exit 1; } + printf "\n" + [[ ! "$reply" =~ [Yy] ]] && { printf "Aborting...\n"; exit 1; } } tag_commits() { @@ -118,10 +118,10 @@ tag_commits() { done if (( count > 0 )); then - echo + printf "\n" msg "Finished: Added $count new tags. Use \`git push --tags\` to update the remote." else - echo + printf "\n" msg "Finished: No new tags were added." fi } diff --git a/hex2rgb b/hex2rgb index 7be9666..93ab552 100755 --- a/hex2rgb +++ b/hex2rgb @@ -1,21 +1,21 @@ #!/bin/bash [[ -z $1 ]] && { - echo "Usage: ${0##*/} " >&2 + printf "Usage: %s " "${0##*/}" >&2 exit 1 } hex2dec() { for val; do - printf "%3d " 0x$val + printf "%3d " "0x$val" done - echo + printf "\n" } printf "\t\t%3s %3s %3s\n" "R" "G" "B" while read line; do [[ ! $line =~ ^\*color ]] && continue - echo -ne "${line% *}\t" + printf "${line% *}\t" hexcode=${line/\*color* /} hex2dec ${hexcode:1:2} ${hexcode:3:2} ${hexcode:5:2} done < $1 diff --git a/hglink b/hglink index a34cc56..89e0b62 100755 --- a/hglink +++ b/hglink @@ -13,11 +13,11 @@ get_hgroot() { while [[ $curpath && ! -d $curpath/.hg ]]; do curpath=${curpath%/*} done - [[ $curpath ]] && echo "$curpath" + [[ $curpath ]] && printf "%s\n" "$curpath" } usage() { - echo "Usage: ${0##*/} [ -l linenum ] [ -b ] [ hash ]" + printf "Usage: %s [ -l linenum ] [ -b ] [ hash ]" "${0##*/}" } >&2 while getopts ":bhl:" opt; do @@ -25,8 +25,8 @@ while getopts ":bhl:" opt; do b) OPENINBROWSER=1 ;; h) usage; exit 1 ;; l) LINE=$OPTARG ;; - \:) echo "Argument required for -$OPTARG" ;; - \?) echo "error: bad arg, no bisuit" ;; + \:) printf "Argument required for -%s\n" "$OPTARG" ;; + \?) printf "error: bad arg, no bisuit\n" ;; esac >&2 done shift $(( OPTIND - 1 )) @@ -35,7 +35,7 @@ shift $(( OPTIND - 1 )) fullpath=$(readlink -m "$1") hg_root=$(get_hgroot "$fullpath") -[[ -z $hg_root ]] && { echo "error: '$1' is not in an hg repo"; exit 1; } +[[ -z $hg_root ]] && { printf "error: '%s' is not in an hg repo\n" "$1"; exit 1; } # we need to operate from within the hg repo. if we're not in it, go there [[ ${PWD#$hg_root} = $PWD ]] && cd $hg_root @@ -53,7 +53,7 @@ rev=${2:-$(hg log -r $remotetip | awk -F: 'NR == 1 { print $3 }')} # relative path from repo root to file relpath=${fullpath#$hg_root/} if [[ -z $relpath ]]; then - echo "error: failed to determine path to $1. tell dave he sucks at bash" + printf "error: failed to determine path to %s. tell dave he sucks at bash\n" "$1" exit 1 fi @@ -64,11 +64,11 @@ urlout="${remotepath}/file/$rev/$relpath${LINE:+#l$LINE}" if type -P curl >/dev/null; then # hgweb kindly responds with a 404 on an invalid link -- so let's validate! if ! curl -sf "$urlout" >/dev/null; then - echo "error: failed to create a valid link to '$1'. check your repo and filepath" + printf "error: failed to create a valid link to '%s'. check your repo and filepath\n" "$1" exit 1 fi fi -# echo or open in browser -(( OPENINBROWSER )) && ${BROWSER:-chromium} "$urlout" || echo "$urlout" +# print or open in browser +(( OPENINBROWSER )) && ${BROWSER:-chromium} "$urlout" || printf "%s\n" "$urlout" diff --git a/list2html b/list2html index 924b03e..13eb9bf 100755 --- a/list2html +++ b/list2html @@ -1,41 +1,36 @@ #!/bin/bash -if [[ $# -ne 2 ]]; then - echo "Usage: $0 " >&2 - exit 1 -fi +(( $# != 2 )) && { printf "Usage: %s \n" "${0##*/}"; exit 1; } >&2 # Redirect STDOUT to an html file exec >> output.html # Start table -echo "" +printf "
\n" count=0 # Initialize a counter for columns while read line; do - if [[ $count -eq 0 ]]; then - # We're at the start of a new row, open it. - printf "\t\n" - fi - - if [[ $count -lt $1 ]]; then - # Print next line from data file - printf "\t\t\n" "$line" - fi - - (( count++ )) - - if [[ $count -eq $1 ]]; then - # We're at the end of a row, close it. - printf "\t\n" - count=0 - fi -done < $2 + if [[ $count -eq 0 ]]; then + # We're at the start of a new row, open it. + printf "\t\n" + fi + + if [[ $count -lt $1 ]]; then + # Print next line from data file + printf "\t\t\n" "$line" + fi + + (( count++ )) -if [[ $count -ne 0 ]]; then - # Kludge for when columns doesn't divide equally into data size + if [[ $count -eq $1 ]]; then + # We're at the end of a row, close it. printf "\t\n" -fi + count=0 + fi +done < $2 + +# Kludge for when columns doesn't divide equally into data size +(( count )) && printf "\t\n" # End table -echo "
%s
%s
" +printf "\n" diff --git a/mancx b/mancx index cc298ee..5481ea8 100755 --- a/mancx +++ b/mancx @@ -11,7 +11,7 @@ XPATH_EXPR='//*[@id="manpage"]/*[self::pre or self::h3]' DETAG='$d;s|]\+>||g;s|<\;|<|g;s|>\;|>|g' usage() { - echo "Usage: ${0##*/} [section] manpage" >&2 + printf "Usage: %s [section] manpage" "${0##*/}" >&2 } # less gets color, else its a NOOP @@ -37,4 +37,4 @@ esac man ${SECTION//[^[:digit:]]/} $PAGE 2>/dev/null && exit manpage=$(curl -s $BASEURL/$PAGE$SECTION | $XMLLINT --xpath "$XPATH_EXPR" - 2>/dev/null | sed "$DETAG" | colorify) -[[ $manpage ]] && "${PAGER:-less}" <<< "$manpage" || echo "No mancx entry for $PAGE" +[[ $manpage ]] && "${PAGER:-less}" <<< "$manpage" || printf "No mancx entry for %s\n" "$PAGE" diff --git a/pkgfile b/pkgfile index 32d1291..c4a0eec 100755 --- a/pkgfile +++ b/pkgfile @@ -18,7 +18,7 @@ createfileball() { [[ -f repos.files.tar.gz ]] && rm repos.files.tar.gz mkdir -p {testing,core,extra,community{,-testing}} - echo -n "Downloading and extracting repo tarballs... " + printf "Downloading and extracting repo tarballs... " for repo in "${repos[@]}"; do ( curl -s "${mirror/\$repo/$repo/}/$repo.files.tar.gz" | tar -xz --wildcards -C $repo '*/files' @@ -29,11 +29,11 @@ createfileball() { ) & done wait - echo "done!" + printf "done!\n" - echo -n "Creating master file tarball... " + printf "Creating master file tarball... " tar czf repos.files.tar.gz * - echo "done!" + printf "done!\n" rm -r "${repos[@]}" } @@ -49,7 +49,7 @@ whoowns() { local needle="${1//\//\\/}" tar -Oxvf "$CACHEDIR/repos.files.tar.gz" |& awk '/%FILES%/{ pkg = prev; next } { sub("/files", ""); prev = $0 } - /'"$needle"'[^\/]+$/{ printf "%-30s %s\n",pkg,$0 }' + /'"$needle"'/{ printf "%-30s %s\n",pkg,$0 }' } [[ $1 ]] || exit 1 diff --git a/pp b/pp index b6a6dd2..e02d278 100755 --- a/pp +++ b/pp @@ -23,7 +23,7 @@ done (( !SYNC || BORING_OPT )) && exec pacman $@ -(( UID != 0 )) && { echo "Must be root!"; exit 1; } >&2 +(( UID != 0 )) && { printf "Must be root!\n"; exit 1; } >&2 # find alternate pacman cache location paccache=$(awk -F' *= *' '/[^#]CacheDir/{ print $2 }' /etc/pacman.conf) @@ -34,7 +34,7 @@ unset paccache IFS=$'\n' read -r -d'\0' -a pkgs < <(pacman -p "${PACARGS[@]}" | grep -E '^(ht|f)tp') # exit on null array -[[ -z "${pkgs[@]}" ]] && { echo "Nothing to do!"; exit 0; } +[[ -z "${pkgs[@]}" ]] && { printf "Nothing to do!\n"; exit 0; } # create a dl manifest, so we don't pass superfluous URLs to aria manifest=() @@ -43,9 +43,9 @@ for pkg in "${pkgs[@]}"; do done if [[ ${manifest[@]} ]]; then - echo ":: Packages to be downloaded:" + printf ":: Packages to be downloaded:\n" for pkg in "${manifest[@]}"; do - echo " ==> ${pkg##*/}" + printf " ==> %s\n" "${pkg##*/}" done fi @@ -56,6 +56,6 @@ for arg; do ARGS+=("$arg") done -aria2c --dir "$PACCACHE" -i - < <(for pkg in "${manifest[@]}"; do echo "$pkg"; done) +aria2c --dir "$PACCACHE" -i - < <(for pkg in "${manifest[@]}"; do printf "%s" "$pkg"; done) (( DL_ONLY )) || pacman "${ARGS[@]}" diff --git a/randomJunk b/randomJunk index a3a71b3..4cc3675 100755 --- a/randomJunk +++ b/randomJunk @@ -3,8 +3,8 @@ ALLOWEDCHARS='[:alnum:][:punct:]' if [[ $# -eq 0 ]]; then - echo "Usage: ${0##*/} [output quantity]" >&2 - exit 1 + printf "Usage: %s [output quantity]" "${0##*/}" >&2 + exit 1 fi quantity=${2:-1} diff --git a/sabs b/sabs index a7477f4..f2fe1bd 100755 --- a/sabs +++ b/sabs @@ -17,23 +17,23 @@ getrepo() { fi } -[[ -z $1 ]] && { echo "Usage: ${0##*/} targets..."; exit 1; } +[[ -z $1 ]] && { printf "Usage: %s targets...\n" "${0##*/}"; exit 1; } for pkg; do # read only the first, repo is only of mild importance read repo _ < <(getrepo $pkg) - [[ -z $repo ]] && { echo "error: package \`$pkg' not found"; continue; } + [[ -z $repo ]] && { printf "error: package \`%s' not found" "$pkg"; continue; } case $repo in @(community|multilib)*) repo=community ;; *) repo=packages ;; esac - [[ -d $pkg ]] && { echo "error: directory \`$pkg' already exists"; continue; } + [[ -d $pkg ]] && { printf "error: directory \`%s' already exists" "$pkg"; continue; } svn export "$svnrepo/$repo/$pkg/trunk" $pkg >/dev/null && - echo ":: checked out $pkg" || - echo "error: failed to get package \`$pkg'" + printf ":: checked out %s\n" "$pkg" || + printf "error: failed to get package \`%s'\n" "$pkg" done diff --git a/simplentp b/simplentp index 4e87233..f866e9d 100755 --- a/simplentp +++ b/simplentp @@ -5,11 +5,11 @@ timeserver="time.nist.gov" clockset() { - echo "Setting hwclock to localtime from time.nist.gov..." + printf "Setting hwclock to localtime from time.nist.gov...\n" hwclock --set --date="$(awk '{if (NF > 1) print $2,$3 " UTC"}' < /dev/tcp/$timeserver/13)" || return 1 - echo "Sync'ing hwclock to system..." + printf "Sync'ing hwclock to system...\n" hwclock -s - echo "The time is now:" $(hwclock) + printf "The time is now: %s" "$(hwclock)" return 0 } diff --git a/vbox b/vbox index 5d071a9..dc7ddec 100755 --- a/vbox +++ b/vbox @@ -56,12 +56,7 @@ connect_vm() { exit 1 fi - echo -n "[vbox] password for `id -nu`: " - STTY_ORIG=`stty -g` - stty -echo - read PASSWORD - echo - stty $STTY_ORIG + read -s -p "[vbox] password for $(id -nu): " PASSWORD if ! pgrep VBoxHeadless; then VBoxHeadless -startvm "$1" & diff --git a/volOSD b/volOSD index c6eb10c..ec41892 100755 --- a/volOSD +++ b/volOSD @@ -36,7 +36,7 @@ get_icon () { icon_name+="muted" fi - echo $icon_name + printf "$icon_name" } oss_adjust () { diff --git a/walk b/walk index cdd441d..49f078d 100755 --- a/walk +++ b/walk @@ -21,7 +21,7 @@ get_pwd_contents() { [[ -d $f ]] && dir+=("$f") || nondir+=("$f") done - echo "${dir[@]}" "${nondir[@]}" + printf "%q\n" "${dir[@]}" "${nondir[@]}" } walk() { @@ -31,8 +31,8 @@ walk() { (( indent += $IND_SZ )) pushd "$1" &>/dev/null - [[ $DIRS_FIRST ]] && dir_contents=$(get_pwd_contents) || dir_contents=(*) - for entry in $(get_pwd_contents); do + [[ $DIRS_FIRST ]] && dir_contents=($(get_pwd_contents)) || dir_contents=(*) + for entry in "${dir_contents[@]}"; do [[ -d $entry && ! -L $entry ]] && walk "$entry" || printentry "$entry" done @@ -51,7 +51,7 @@ indent=0 (( $# == 0 )) && DIRS=(.) || DIRS=($@) for basedir in "${DIRS[@]}"; do - cd "$basedir" 2>/dev/null || { echo "Directory not found: '$basedir'" >&2; continue; } + cd "$basedir" 2>/dev/null || { printf "Directory not found: '%s'\n" "$basedir" >&2; continue; } walk "$basedir" done diff --git a/wgetzen b/wgetzen index 50c2b73..71bb05f 100755 --- a/wgetzen +++ b/wgetzen @@ -2,7 +2,7 @@ # wgetzen - a wrapper for wget using zenity -type -P zenity >/dev/null || { echo "zenity binary not found!">&2; exit 1; } +type -P zenity >/dev/null || { printf "zenity binary not found!\n"; exit 1; } >&2 # files: change these if needed/wanted WGETFIFO=/tmp/wgetfifo diff --git a/xo b/xo index d054393..0fc93e8 100755 --- a/xo +++ b/xo @@ -5,7 +5,7 @@ # # Arg check -[[ $# -ne 1 ]] && { echo "Usage: ${0##*/} " >&2; exit 1; } +[[ $# -ne 1 ]] && { printf "Usage: %s \n" "${0##*/}" >&2; exit 1; } # Declare an associative array to keep track of our file types. # Index elements can be a full MIME type (e.g. image/png), just