UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 1st, 2004, 04:14 PM
JohnSaunders JohnSaunders is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 212 JohnSaunders User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 35 sec
Reputation Power: 7
Space causing problems in shells script

Can somebody tell me why when I run this line it says "Deleted" is not found when it should be looking for a file named "Deleted Messages"? Unfortunately, I cannot just change the file name.

Code:
for FILE in `find $HOME -name "Deleted Messages" -print` 

Reply With Quote
  #2  
Old December 2nd, 2004, 06:23 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 49 m 57 sec
Reputation Power: 9
the worst you can do in unix is: filenames containing special
characters like: spaces, newlines, &*¦()? and so on
nota in *nix all except / and the NULL-terminator-char are LEGAL
99% all scripts and most of other progs will crash on this, because
not the shell, but programmers never assume a newline in file name

back to your Q: masking " i mean \" will probalily solve it
my Q: who said you, there is ONLY ONE space (special char) in that string ??
so may be you have to use grep or sed, something like
find $HOME ¦ sed -n '/elete.*essage/p'
NOTA: on modern find, -print is obsolete

Reply With Quote
  #3  
Old December 2nd, 2004, 08:12 PM
igrokme igrokme is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 igrokme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You are lacking quotes around your backticks. All subsequent uses of $FILE will also need double quotes.

Although that should be done anyhow (to guard against special characters), have you considered a cd into "$HOME/Deleted Messages" before running the find(1)?

Code:
for FILE in "`find $HOME -name "Deleted Messages" -print`"
  ls -l "$FILE"
  process "$FILE"
  ...
done


if your find(1) supports it you might consider using -print0 and |xargs -0 instead. Of course, find(1) -exec runme args '{}' \; will work as well but if xargs is appropriate it saves you the extra exec(2)s.

Code:
find $HOME -name "Deleted Messages" -print0 | xargs -0 runme args

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Space causing problems in shells script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway