On 22/04/12 08:34, Cam Hutchison wrote:Or just quote the entries like
Soare Catalin<lolinux.soare@gmail.com> writes:
The script will take files or dirs as parameters and will back them up in a
presefined location, using tar. Problems arise when it will encounter files
or directories which contain spaces in their names.
then #is it an existing directory?
BK_LIST="$BK_LIST ${PARAM}"
here...
else
if [ -f "$PARAM" ]; then #is it an existing file?
BK_LIST="$BK_LIST ${PARAM}"
.... and here.
As you build up BK_LIST, you lose the ability to tell which spaces are
the ones you added, or were already in $PARAM. You end up treating all
spaces as word separators.
To fix this, you want to make BK_LIST an array:
BK_LIST=()
# or declare -a BK_LIST, but I prefer the former
Append to the array with +=
BK_LIST+="${PARAM}"
Expand the array, preserving spaces:
tar -cjf $BK_FULLPATH "${BK_LIST[@]}"
BK_LIST="$BK_LIST \"${PARAM}\""
(apologies if thi mail goes through twice, I got a bounce on my earlier attempt)
--
DomArchive: [🔎] 4F945B2C.3090307@rpdom.net" target="_blank">http://lists.debian.org/[🔎] 4F945B2C.3090307@rpdom.net
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org