|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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` |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Space causing problems in shells script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|