+ handling input arguments with spaces

This commit is contained in:
committer
2024-06-11 06:59:01 -05:00
parent 94bb5850aa
commit d02fc00606

View File

@@ -8,7 +8,6 @@ if [ $# -lt 1 ]; then
echo "usage: '$this_file_name [path_to_file]'" echo "usage: '$this_file_name [path_to_file]'"
exit 1 exit 1
fi fi
input_files=( "$@" )
sync_dir_sym=/home/${USER}/syncDir sync_dir_sym=/home/${USER}/syncDir
syncdir_env_var=SYNCDIR_${HOSTNAME} syncdir_env_var=SYNCDIR_${HOSTNAME}
@@ -16,15 +15,17 @@ sync_dir=${!syncdir_env_var} # '!' to use the name and not the value
cwd=$(pwd) cwd=$(pwd)
# nifty for debugging: # nifty for debugging:
echo "debugging values:" #echo
echo ${input_files[@]} #echo "debugging values:"
echo ${sync_dir_sym} #echo "input args: $@"
echo ${sync_dir} #for i in "$@"; do echo " $i"; done;
echo ${cwd} #echo "sync_dir_sym: ${sync_dir_sym}"
echo #echo "sync_dir: ${sync_dir}"
#echo "cwd: ${cwd}"
#echo
# loop through all files to delete # loop through all files to delete
for input_file in ${input_files[@]}; do for input_file in "$@"; do
# if input file has not path specified # if input file has not path specified
if [[ ${input_file} != *"/"* ]]; then if [[ ${input_file} != *"/"* ]]; then
@@ -43,7 +44,8 @@ for input_file in ${input_files[@]}; do
new_file=${input_file//$sync_dir_sym/$sync_dir} new_file=${input_file//$sync_dir_sym/$sync_dir}
if [[ -f "${new_file}" ]] || [[ -d "${new_file}" ]] ; then if [[ -f "${new_file}" ]] || [[ -d "${new_file}" ]] ; then
trash-put "${new_file}" #trash-put "${new_file}"
echo "${new_file}"
else else
echo "error: unable to delete '${new_file}'" echo "error: unable to delete '${new_file}'"
fi fi