From 00626fe2703dbfc40f8b488af4d845521bc49ab8 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 27 Feb 2014 11:20:31 -0500 Subject: Add quoting, remove backticks, use $PWD * http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08 Fixes #46. This does not handle quotes around `$@`. That is taken separately in #53. --- bin/rcup | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'bin/rcup') diff --git a/bin/rcup b/bin/rcup index be2e4c3..340ab5c 100755 --- a/bin/rcup +++ b/bin/rcup @@ -1,29 +1,29 @@ #!/bin/sh -: ${RCM_LIB:=`dirname $0`/../share/rcm} -. $RCM_LIB/rcm.sh +: ${RCM_LIB:=$(dirname "$0")/../share/rcm} +. "$RCM_LIB/rcm.sh" link_or_copy() { $DEBUG "link_or_copy $1" - local sigil=$1 + local sigil="$1" if [ "x$sigil" = "xX" ]; then - echo $CP + echo "$CP" else - echo $LN + echo "$LN" fi } link_file() { local src="$1" local dest="$2" - local sigil=$3 + local sigil="$3" if [ -h "$dest" ]; then $RM -f "$dest" fi - action=`link_or_copy $sigil` + action="$(link_or_copy "$sigil")" $DEBUG "$action $src $dest" $action "$src" "$dest" } @@ -31,17 +31,16 @@ link_file() { replace_file() { local src="$1" local dest="$2" - local sigil=$3 + local sigil="$3" $DEBUG replace_file "$1" "$2" $3 - $RM -rf $dest - link_file "$src" "$dest" $sigil + $RM -rf "$dest" + link_file "$src" "$dest" "$sigil" } is_nested() { - echo $1 | sed "s:$DEST_DIR/::" | grep -q / - return $? + echo "$1" | sed "s:$DEST_DIR/::" | grep -q '/' } is_identical() { @@ -51,7 +50,7 @@ is_identical() { handle_dir() { local dest="$1" - $DEBUG handle_dir $1 + $DEBUG "handle_dir $1" dirname "$dest" | xargs $MKDIR -p } @@ -59,29 +58,29 @@ handle_dir() { handle_file() { local src="$1" local dest="$2" - local sigil=$3 + local sigil="$3" - $DEBUG handle_file $1 $2 $3 + $DEBUG "handle_file $1 $2 $3" if [ -e "$dest" ]; then if is_identical "$src" "$dest"; then $VERBOSE "identical $dest" elif [ $REPLACE_ALL -eq 1 ]; then - replace_file "$src" "$dest" $sigil + replace_file "$src" "$dest" "$sigil" else $PROMPT "overwrite ${dest}? [ynaq]" read overwrite - case $overwrite in + case "$overwrite" in a) REPLACE_ALL=1 - replace_file "$src" "$dest" $sigil + replace_file "$src" "$dest" "$sigil" ;; - y) replace_file "$src" "$dest" $sigil ;; + y) replace_file "$src" "$dest" "$sigil" ;; q) exit 1 ;; *) $VERBOSE "skipping $dest" ;; esac fi else - link_file "$src" "$dest" $sigil + link_file "$src" "$dest" "$sigil" fi } @@ -128,15 +127,15 @@ handle_command_line() { shift $(($OPTIND-1)) if [ $always_copy -eq 1 ]; then - LN=$CP + LN="$CP" fi handle_common_flags rcup $version $verbosity - tags=${arg_tags:-$TAGS} - DOTFILES_DIRS=${dotfiles_dirs:-$DOTFILES_DIRS} + tags="${arg_tags:-$TAGS}" + DOTFILES_DIRS="${dotfiles_dirs:-$DOTFILES_DIRS}" RUN_HOOKS=$run_hooks - files=$@ + files="$@" for tag in $tags; do LS_ARGS="$LS_ARGS -t $tag" @@ -160,7 +159,7 @@ handle_command_line() { LS_ARGS=-F -handle_command_line $* +handle_command_line $@ : ${DOTFILES_DIRS:=$DOTFILES_DIRS $DEFAULT_DOTFILES_DIR} run_hooks pre up @@ -168,19 +167,19 @@ run_hooks pre up saved_ifs=$IFS IFS=' ' -for dest_and_src in `lsrc $LS_ARGS`; do +for dest_and_src in $(lsrc $LS_ARGS); do IFS=: set $dest_and_src IFS=$saved_ifs dest="$1" src="$2" - sigil=$3 + sigil="$3" if is_nested "$dest"; then handle_dir "$dest" fi - handle_file "$src" "$dest" $sigil + handle_file "$src" "$dest" "$sigil" done run_hooks post up -- cgit v1.2.3