Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-16-2006, 09:53 AM   #1
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Rep: Reputation: 30
shell script:filename containing space !

Hi, i wrote a simple linux shell script to modify my nokia contacts files and add 050 befor every number in every contact file. it worked fine with all files except filenames that contain space.

for example file name "Mr John Smith.vcf", it show this error:
sed: can't read Mr: No such file or directory
sed: can't read John: No such file or directory
sed: can't read Smith.vcf: No such file or directory
mv: target `Smith.vcf' is not a directory

for a in *.vcf
sed 's/.*CELL:\([0-9]*\).*/TEL;CELL:050\1/' $a > 1$a |
 mv 1$a $a
any idea !

sorry for my English
Old 12-16-2006, 11:01 AM   #2
Senior Member
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
Put double quotes around the filename, such as "$a" and "l$a".
Old 12-16-2006, 02:06 PM   #3
Registered: Jul 2005
Location: U.A.E
Distribution: FreeBSD,Fedora,Solaris,AIX
Posts: 168

Original Poster
Rep: Reputation: 30
oops i tried "" with *.vcf

thanks uselpa, its working fine now.
Old 12-16-2006, 07:46 PM   #4
Registered: Jun 2005
Location: CA, USA
Distribution: Gentoo
Posts: 165

Rep: Reputation: 30
You can also "escape" the space character with backslashes.

this is a text file.txt
could be
this\ is\ a\ text\ file.txt


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
omitting space in shell script Fond_of_Opensource Linux - Newbie 10 11-18-2006 10:18 AM
for script: listing files which have space in filename hamish Linux - General 5 10-22-2005 10:25 AM
Space Key in Shell Script joshlamerritt Linux - General 1 02-20-2004 02:31 PM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM
Changing to a directory with a space in the filename? guitargeek Linux - General 5 02-13-2003 06:38 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:22 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration