On my Centos 6.2 I have this bash script:
[le_me]$ cat get.nb
#! /bin/bash
/usr/bin/wget -O /var/www/html/leFile.xml http://www.leSite.com/leFeed.xml
[le_me]$ source getFeeds.nb
: command not found
--2012-06-22 12:46:18-- http://www.leSite.com/leFeed.xml%0D
Resolving www.leSite.com... 1.2.3.4
Connecting to www.leSite.com|1.2.3.4|:80... connected.
HTTP request sent, awaiting response... 406 Not Acceptable
2012-06-22 12:46:18 ERROR 406: Not Acceptable.
The strange thing for me is that when I run this command
/usr/bin/wget -O /var/www/html/leFile.xml http://www.leSite.com/leFeed.xml
in the console, everything works fine and the file is downloaded without a problem.
I did google about it and I noticed this %0D which supposed to be a carrige return character, and I tried putting another space after the link like so: http://www.leSite.com/leFeed.xml[spaceChar]
and I got the file downloaded but I’m concerned about the command not found output and fetching that carrige return in the end (which ofc I know it’s because of the space, but now at least I downloaded the file I originally wanted):
[le_me]$ source get.nb
: command not found
--2012-06-22 13:05:26-- http://www.leSite.com/leFeed.xml
Resolving www.leSite.com... 2.17.249.51
Connecting to www.leSite.com|2.17.249.51|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35671435 (34M) [application/atom+xml]
Saving to: “/var/www/html/leFile.xml”
100%[=================================>] 35,671,435 37.2M/s in 0.9s
2012-06-22 13:05:27 (37.2 MB/s) - “/var/www/html/leFile.xml” saved [35671435/35671435]
--2012-06-22 13:05:27-- http://%0D/
Resolving \r... failed: Name or service not known.
wget: unable to resolve host address “\r”
FINISHED --2012-06-22 13:05:27--
Downloaded: 1 files, 34M in 0.9s (37.2 MB/s)
Can anyone shed some light on this please?
Your script file apparently has DOS-style lines, and the carriage return character is interpreted as just another character in the command line. If you have no space after the URL, it is interpreted as the last character of the URL; if you have a space, it is interpreted as a separate one-character parameter.
You should save your script file with UNIX-style lines. How you do that depends on your editor.