1

I have a simple shell script which is as follows.

#!/usr/bin/env bash
wget -O glove.840B.300d.zip http://nlp.stanford.edu/data/glove.840B.300d.zip

When I run it using sh command, I get the following error.

--2017-06-29 20:35:41--  http://nlp.stanford.edu/data/glove.840B.300d.zip%0D
Resolving nlp.stanford.edu (nlp.stanford.edu)... 171.64.67.140
Connecting to nlp.stanford.edu (nlp.stanford.edu)|171.64.67.140|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://nlp.stanford.edu/data/glove.840B.300d.zip%0d [following]
--2017-06-29 20:35:41--  https://nlp.stanford.edu/data/glove.840B.300d.zip%0d
Connecting to nlp.stanford.edu (nlp.stanford.edu)|171.64.67.140|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-06-29 20:35:41 ERROR 404: Not Found.

But when I run the same wget command (written in the shell script) from terminal, it works fine! What is the problem in my shell script? What I am missing?

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161

2 Answers2

3

Note the %0d in the end. It seems like somewhere along the way, you used DOS/Windows line endings in a Linux environment. that %0d is a "carriage return" character, since in Windows CR LF (carriage return line feed) is used for newlines. Unix expects just LF and includes the extra character in the command line.

See Difference between CR LF, LF and CR line break types?

cnettel
  • 1,024
  • 5
  • 7
0

You have edited your script using something which uses DOS line-endings. So wget is seeing a spurious carriage-return (hex 0D) at the end of the line.

Replace the DOS line-endings (CR-LF) with Unix ones (LF) and all will be well.