![]() |
filenames with spaces
I am trying to process a directory and determine attributes of each file. I am using a for x in $( ls ) loop to iterate through the directory, but files with spaces in the name populate ${x} for each word. E.G.
A simple script to list directories for i in $( ls ); do if [ -d "${i}" ]; then echo ${i}; fi; done If I have a subdirectory called "This is a file" (without the quotes) It will look for files: - This Is A File which do not exist. Anyone have any ideas how best to list the directory and just get the filenames individually? Many Thanks. |
Change the IFS variable like so. (For more info on this variable, try man bash and search for IFS)
Code:
|
Try
Code:
ls | awk '{ print }' |
Check this out :
Code:
PS : Don't forget to put quotes around $i |
koodoo wins
or: Code:
|
I use the following
oldIfs=$IFS IFS=' ' l=$(find $srcFolder -iname '*.jpg') for jpgitem in $l; do IFS=$oldIfs # do what to do # cp -v "$jpgitem" "$targetFolder IFS=' ' done RGummi |
| All times are GMT -5. The time now is 08:53 PM. |