Jonathon Conte wrote:
> I want to write a script that uses ls and grep to send a filtered list
> of files to tar to create an archive. I'm getting hung up on filenames
> that contain spaces. What looks wrong below?
>
> jconte@peregrine:~/Desktop/spaces$ ls
> filename with spaces
> jconte@peregrine:~/Desktop/spaces$ ls -Q
> "filename with spaces"
> jconte@peregrine:~/Desktop/spaces$ tar -cf ../test.tar $(ls -Q)
> tar: "filename: Cannot stat: No such file or directory
> tar: with: Cannot stat: No such file or directory
> tar: spaces": Cannot stat: No such file or directory
> tar: Error exit delayed from previous errors
>
> Thanks for any suggestions.
> Jonathon
>
> _________________________________________________________________
> Interest Rates NEAR 39yr LOWS! $430,000 Mortgage for $1,299/mo -
> Calculate new payment
> http://www.lowermybills.com/lre/index.jsp?sourceid=lmb-9632-19132&moid=14888
>
>
> -----------------------------------------------------------------------
> This list is provided as an unmoderated internet service by Networked
> Knowledge Systems (NKS). Views and opinions expressed in messages
> posted are those of the author and do not necessarily reflect the
> official policy or position of NKS or any of its employees.
>
Jonathon,
Write a script or add to your script something that will get rid of the
spaces in the filename, replace them with a dash or underscore. Spaces
in file names usually are used on Window platforms.
Something like this:
for file do
# Change spaces to dashes
lfile=`echo $file | tr ' ' '\-'`
# Get rid of multiple dashes or dashes in beginning or end
lfile=`echo $lfile | sed -e 's/[_][_][_]*/_/g' -e 's/_\././g' -e
's/^_//g'`
if [ "$file" != "$lfile" ]; then
if [ ! -f "$lfile" ]; then
mv "./$file" $lfile
echo "$lfile" fixed
else
echo "$lfile" exists
fi
fi
done
(script thanks to my friend Barry Fishman)
John
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 16:14:51 EDT