Results 1 to 2 of 2
Hi all!
I have a problem that drives me nuts. In essence; I have a file with a filename that contains a whitespace, say:
foo bar.txt
I have assigned the ...
- 05-27-2011 #1Just Joined!
- Join Date
- Nov 2010
- Location
- 08 - Stockholm
- Posts
- 19
bash and whitespace, again! [SOLVED]
Hi all!
I have a problem that drives me nuts. In essence; I have a file with a filename that contains a whitespace, say:
foo bar.txt
I have assigned the name to a variable, $FILE (FILE="foo bar.txt"). Here comes the odd thing; in a terminal window, I can do:
cp "$FILE" "$FILE.copy"
Without any kind of problems or errors. However, when I do the EXACT same operation in a script. I get the following error messages:
Can't open /Users/me/Desktop/foo: No such file or directory.
Can't open bar.tab: No such file or directory.
Can't open /Users/me/Desktop/foo: No such file or directory.
Can't open bar.tab: No such file or directory.
Can't open /Users/me/Desktop/foo: No such file or directory.
Can't open bar.tab: No such file or directory.
Can't open /Users/me/Desktop/foo: No such file or directory.
Can't open bar.tab: No such file or directory.
Can't open /Users/me/Desktop/foo: No such file or directory.
Can't open bar.tab: No such file or directory.
(As you can see, this is done on a Mac, hold your horses, I wrote the script on my GNU/Linux machine - I am trying to adapt it for work, where we are using Apple. Not my choice. Put the rocks down...)
I simply cannot understand why it works in a terminal window, and not in my script. Actually, it still WORKS - but I get the annoying error messages that I cannot even redirect to /dev/null.
I guess this leads to two questions.
A) Most importantly; why? What am I missing?
B) It works, but I have to get rid of the error messages in the script. I have tried the following:
cp "$FILE" "$FILE.copy" &>errors
But like I wrote above, I cannot even redirect the annoying error messages.
Any help would be appreciated. Thanks for reading this.
HMWLast edited by HMW; 05-27-2011 at 11:07 AM.
- 05-27-2011 #2Just Joined!
- Join Date
- Nov 2010
- Location
- 08 - Stockholm
- Posts
- 19
Fellow hackers!
Sometimes... please ignore the question above. I was doing everything right, but in the wrong place!
Turns out I had forgotten the quotes in the previous function in my script *sigh*. It works just fine, I was simply trying to fix something that wasn't broken, instead of finding the root of the problem.
This matter is solved. Thanks to those who took time and read the post.
Best,
HMW


Reply With Quote