Bash - Script error if folder with spaces

ساخت وبلاگ

Vote count: 0

I have this script

#!/bin/bash
rename_files() { title="${1##*${2} - }" for filename in "$1/"*.*; do case "${filename##*.}" in doc|doc|doc) mkdir -p -m 777 "/Users/Desktop/Documents Share/Downloaded/${title}" new_path="/Users/Desktop/Documents Share/Downloaded/${title}/${title}.${filename##*.}" let "iters=1" while [ -f $new_path ] ; do new_path=$new_path"$iters" let "iters++" done echo "moving $filename -> $new_path" mv "${filename}" "${new_path}" ;; esac done
}
rename_category() { for path in "/Users/Desktop/Documents Share/Downloads/${1}"*; do rename_files "$path" "$1" done
}
rename_category DOC

This script automatically moves and renames files contained in /Users/Desktop/Documents Share/Downloaded. All is working fine if I use a folder called Documents instead of Documents Share. I tried to do use Documents Share but it doesn't work.

Here is the error log

/Users/Desktop/Script.sh: line 11: [: /Users/Desktop/Documents: binary operator expected

How can I solve it?

asked 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 370 تاريخ : شنبه 29 اسفند 1394 ساعت: 18:22