LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-28-2006, 03:18 PM   #1
kyosuke
LQ Newbie
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 9

Rep: Reputation: 0
Getting rm to like spaces in filename


Hi everyone,

Now my problem is a bit of an obscure one, but bear with me. I wrote a little program to extract a complete filename from a log file, and now I want to have rm delete that file by entering:

rm `filenamefinder`

Unfortunately, the file path the filenamefinder program provides has a space in it. I made two versions of the finder program with the following outputs, minus quotes:

"/onedirectory/another/Spaced Directory/foo.bar"
"/onedirectory/another/Spaced\ Directory/foo.bar"

The problem is that rm gives the following errors:

[ky@tails ~]$ rm `~/filenamefinder`
rm: cannot remove `/onedirectory/another/Spaced': No such file or directory
rm: cannot remove `Directory/foo.bar': No such file or directory

[ky@tails ~]$ rm `~/filenamefinder2`
rm: cannot remove `/onedirectory/another/Spaced\\': No such file or directory
rm: cannot remove `Directory/foo.bar': No such file or directory

So basically whether I have "Spaced Directory" or "Spaced\ Directory" being output by my program, rm still thinks they are two different names. How can I convince it they're one?

Thanks,
-K.W.

P.S. folder names changed to protect the innocent
 
Old 02-28-2006, 03:31 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,743

Rep: Reputation: 299Reputation: 299Reputation: 299
Shell expansion of commands allows one to give multiple inputs to a command which are delineated: space, tab, comma, semicolon, etc.

The shell is interpreting the command to rm something as two parameters, because of the space in the path to the file.

Try enclosing the /path/to/file name in double quotes, "/path/to/file name" to prevent shell expansion.

rm `"filenamefinder"`
 
Old 02-28-2006, 04:55 PM   #3
kyosuke
LQ Newbie
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 9

Original Poster
Rep: Reputation: 0
Well, you lead me to the solution, even if what you told me wasn't exactly it.

rm `"filenamefinder"` didn't work, but rm "`filenamefinder`" did, and only when I used it with the version of the program that _doesn't_ put a backslash before spaces as an escape character.

So, thanks for getting me on the right track and leading me to a solution!

-K.W.
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to remove capitalisation and spaces form a filename scuzzman Programming 11 05-18-2008 12:28 PM
Script: lame stumbles on spaces in filename browny_amiga Linux - General 5 05-14-2008 08:14 AM
change uploaded files from filename.avi to filename.avi.html like www.rapidshare.de latheesan Linux - Newbie 3 06-16-2005 04:33 AM
filename- and filename~ files? slinky2004 Linux - Newbie 5 10-17-2004 10:32 PM
spaces in filename in console...? AlThor880 Linux - Software 4 01-09-2003 02:36 PM


All times are GMT -5. The time now is 09:25 AM.

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