moving a file having blanks in its name

Hi ,
i need to write a simple to script in KSh to move some files ,
but these files have spaces in there name, resulting in error in transfering

eg i have following files
30222_Deal Ticket_20071227203.csv
30222_Deal Ticket_20071227204.csv
30222_Deal Ticket_20071227205.csv

and i want to move them to some other folder ,
i am using follwing script

for i in `ls *20071227*`
do
cp "$i" ./NewFolder
done

this script gives error
cp: cannot access 30222_Deal
cp: cannot access Ticket_20071227203.csv

Please help :confused:

Look like you don't have permissions to read that files.

Permissions are available,
just try to replicate the scenario mentioned above

You don't have any space in your file names and you don't really need ls

$ for i in *20071227*; do echo cp $i ./NewFolder;done
cp Ticket_20071227203.csv ./NewFolder
cp Ticket_20071227204.csv ./NewFolder
cp Ticket_20071227205.csv ./NewFolder
$ ls NewFolder/
Ticket_20071227203.csv  Ticket_20071227204.csv  Ticket_20071227205.csv

Your problem is:

Not only is ls unnecessary, it is breaking your script.

Use wildcard expansion directly:

cp *20071227* ./NewFolder

Similarly, when you need to use a loop (which you don't in this case):

for i in *20071227*
do
  cp "$i" ./NewFolder
done

actually these are 3 files
1.) 30222_Deal Ticket_20071227203.csv
2.) 30222_Deal Ticket_20071227204.csv
3.) 30222_Deal Ticket_20071227205.csv

and they have spaces in between

oh, yes cp is working without ls
but can any one explian how and why this is creating a problem

Please post your sample data with the code tags to preserve indentation. This makes it much easier to read.

And here is the output using your example:

$ ls
30222_Deal Ticket_20071227203.csv       30222_Deal Ticket_20071227205.csv
30222_Deal Ticket_20071227204.csv       NewFolder
$ ls NewFolder/
$ for i in *20071227*;do cp "$i" ./NewFolder;done
$ ls
30222_Deal Ticket_20071227203.csv       30222_Deal Ticket_20071227205.csv
30222_Deal Ticket_20071227204.csv       NewFolder
$ ls NewFolder/
30222_Deal Ticket_20071227203.csv       30222_Deal Ticket_20071227205.csv
30222_Deal Ticket_20071227204.csv