hi all,
i have a problem with my script. hope someone can help me.
i have a many files that named with space characters, like "test test.mp3"
in bash when i want copy this file bash help me to complete the name like this:
"cp ./test\ test.mp3 /tmp" (i know that "\" character means that bash dont see the next character and for this example bash will ignore space character after test)
here is my problem, that i want to use variable for this in my script to copy this type of named files (i mean with space characters) automatically.
when i use this type these happen:
[root@localhost ~]# C=$(grep -wi "MP3" /tmp/sync | awk -F: '{print $1}'|head -n3|tail -n1)
[root@localhost ~]# echo $C
/media/ftp/Payam test .mp3
[root@localhost ~]# cp $C .
cp: cannot stat `/media/ftp/Payam': No such file or directory
cp: cannot stat `test': No such file or directory
cp: cannot stat `.mp3': No such file or directory
[root@localhost ~]#
now how can i solve my problem?? i used some method like:
[root@localhost ~]# C=$(grep -wi "MP3" /tmp/sync | awk -F: '{print $1}'|head -n3|tail -n1|sed 's/ /\\ /g')
[root@localhost ~]# echo $C
/media/ftp/Payam\ test\ .mp3
[root@localhost ~]# cp $C .
cp: cannot stat `/media/ftp/Payam\\': Invalid argument
cp: cannot stat `test\\': No such file or directory
cp: cannot stat `.mp3': No such file or directory
[root@localhost ~]#
but nothing happened good.
please help me solve this problem.
tanx.