From 23d085143315d7cbce8c0be18822e96ca5d40889 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 18 Nov 2013 13:31:43 +0100 Subject: [PATCH] Don't use echo for data from the user. --- lib.sh | 16 +++++++++------- setup.sh | 12 +++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib.sh b/lib.sh index 474f638..c55cb0a 100644 --- a/lib.sh +++ b/lib.sh @@ -41,7 +41,7 @@ installed_path() { # Walk PATH. for directory in $PATH; do if test -x "$directory/$1"; then - echo "$directory/$1" + printf '%s\n' "$directory/$1" return 0 fi done @@ -143,9 +143,9 @@ link() { # Get all necessary paths. pwd=`pwd` - base=`echo "$2" | sed "s|\~|$HOME|"` # expand ~, some sh don't do it + base=`printf '%s' "$2" | sed "s|\~|$HOME|"` # expand ~, some sh don't do it base=`dirname "$base"` - source=`echo "$pwd/$1" | sed "s|$base/||"` + source=`printf '%s' "$pwd/$1" | sed "s|$base/||"` target=`basename "$2"` # Go to the directory where the link is going to be created. @@ -155,18 +155,19 @@ link() { # overwriting real files. if ( test -f "$target" && test ! -h "$target" ) || \ ( test -s "$target" && test ! -h "$target" ); then - echo "link(): target '$target' exists already and is no symbolic link!" >&2 + printf "link(): target '%s' exists already and is no symbolic link!" \ + "$target" >&2 exit 1 fi # Make sure the source exists (is file, directory or link). if test ! -f "$source" && test ! -d "$source" && test ! -h "$source"; then - echo "link(): source '$source' doesn't exist!" >&2 + printf "link(): source '%s' doesn't exist!" "$source" >&2 exit 1 fi # Create the new symbolic link; remove the old one if necessary. - echo "link(): linking '$source' to '$target'" + printf "link(): linking '%s' to '%s'\n" "$source" "$target" rm -f "$target" ln -s "$source" "$target" @@ -203,7 +204,8 @@ generate() { echo '# WARNING! DO NOT EDIT THIS FILE! #' >>"$file" echo '###################################' >>"$file" echo >>"$file" - echo "# It was generated from $file$extension on `date`." >>"$file" + printf "# It was generated from '%s' on %s.\n" \ + "$file$extension" "`date`" >>"$file" echo >>"$file" file_tmp="$file" diff --git a/setup.sh b/setup.sh index cf7eb54..2190af1 100755 --- a/setup.sh +++ b/setup.sh @@ -25,13 +25,11 @@ for path in */setup.sh; do # Skip non executable setup.sh files as an easy way to deactivate one. test ! -x "$path" && continue - project=`echo "$path" | sed 's|/setup.sh$||'` + project=`printf '%s' "$path" | sed 's|/setup.sh$||'` - echo "running setup.sh in '$project'" - if ( cd "$project"; ./setup.sh >/dev/null ); then - : - else - echo "$project/setup.sh failed" >&2 + printf "running setup.sh in '%s'\n" "$project" + ( cd "$project" && ./setup.sh >/dev/null ) || { + printf '%s/setup.sh failed\n' "$project" >&2 exit 1 - fi + } done -- 2.43.2