Re: Spaces in file names - watch for arg list too long with ls *
- From: "Nitro" <nitro-57@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 31 Dec 2007 09:14:43 -0500 (EST)
On Mon, 31 Dec 2007 03:31:16 -0900, Floyd L. Davidson wrote:
"Leslie Rhorer" <lrhorer@xxxxxxxxxxx> wrote:
Hey, that works! Thanks.
But it would be a lot easier to just do this:
#!/bin/bash
for file in * ; do
echo "$file"
done
exit 0
The trick is putting quotes around $file. Using `ls -1 *`
is unnecessary, and so is find.
"Dan Mills" <dmills@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:477856c3$0$21094$da0feed9@xxxxxxxxxxxxxxxxx
On Sun, 30 Dec 2007 19:31:45 -0600, Leslie Rhorer wrote:
OK, here's the problem. I need to automatically manipulate the file
names
of a number of files whose filenames have spaces in them.
for file in `ls -1 *`
do
<do stuff>
done
How about something like (untested):
#!/bin/bash
IFS=$'\n'
#IFS is the internal field separator in bash and
#here we set it to be new line only.
for file in $(find . -type f)
do
<stuff with "$file">
done
HTH.
Regards, Dan.
--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@xxxxxxxxxx
Another pitfall using the ls -1 *, if you have a large number of files in teh
output list the command may fail with an argument list too long. (but may be
OK without the astersk,) Depending on your default distribution's compilied
options this may be as few as 2000 files.
Regards,
Bart
.
- References:
- Spaces in file names
- From: Leslie Rhorer
- Re: Spaces in file names
- From: Dan Mills
- Re: Spaces in file names
- From: Leslie Rhorer
- Re: Spaces in file names
- From: Floyd L. Davidson
- Spaces in file names
- Prev by Date: Re: Spaces in file names
- Next by Date: Re: Spaces in file names
- Previous by thread: Re: Spaces in file names
- Index(es):
Relevant Pages
|