[prog] Bash script blues
Kaitlyn
linuxchix at e-wire.org
Thu Aug 25 17:41:13 EST 2005
Hi everyone,
I'm having trouble with a bash script I'm tring to write. The goal
of it is to clean my $HOME by moving files by type into different
directories and email what it did.
One the the file types are .torrents, I want them moved into a
directory, marked with a "_D" infront of each one, and all the ones that
are already marked with _D should be deleted. (I want to read which
files are slated for deletion before they are deleted.
The problem I'm having is making the spaces in the file names be
replaced with an underscore.
What I was trying was this:
[code] for i in `ls -1 $HOUSE |grep .torrent` ; do mv "$i" `echo
"$i" |sed s/\ /_/g` ; done [/code] (House is equated in the first part
of the script)
However I get errors:
kaitlyn at rogue ~/bin/working $ for i in `ls -1 |grep .torrent` ; do mv
"$i" `echo "$i" |sed s/\ /_/g` ; done
mv: cannot stat `this': No such file or directory
mv: cannot stat `is': No such file or directory
mv: cannot stat `torrent.torrent': No such file or directory
kaitlyn at rogue ~/bin/working $ ls
this is torrent.torrent
kaitlyn at rogue ~/bin/working $
I'm fairly sure the problem is that is breaks on spaces, but I'm not
sure how to make it not break on spaces, google didn't have any answers
that I could find, and I've spent about 45 minutes trying to make it
work. Not too sure what to do, so I thought I'd email this list to see
if anyone has any ideas?
--Kaitlyn
More information about the Programming
mailing list