0

I face two problems, whose cause might be the same, which is why I post them in one question.

This is my little shell script:

#!/bin/bash
wget "https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-i686.tar.bz2"

Then I say ./script.

I get bash: ././script: /bin/bash^M: bad interpreter: No such file or directory

Then I say to myself, okay, try bash script instead of ./script.

It seems to work, but the URL is then:

--2013-12-31 12:24:55--  https://phantomjs.googlecode.com/files/phantomjs-1.9.2-
linux-i686.tar.bz2%0D
Resolving phantomjs.googlecode.com... 173.194.69.82, 2a00:1450:4008:c01::52
Connecting to phantomjs.googlecode.com|173.194.69.82|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-12-31 12:25:01 ERROR 404: Not Found.

Do you recognize that my URL has an 2%0D appended in line 2 after the file name?

When I run the command in my shell itself, not as a script, it works totally fine.

Do these two problems have the same root? Why is there a 2%0D appended? I already looked for an empty space but did not find it.

Xiphias
  • 4,468
  • 4
  • 28
  • 51

2 Answers2

4

you edited your script probably with an editor creating DOS line endings (\r\n). Use another editor or convert it with a tool like dos2unix

ensc
  • 6,704
  • 14
  • 22
  • Both problems were indeed solved by the same solution. Thank you very much. After creating the file using `nano` in Linux, it worked. – Xiphias Dec 31 '13 at 12:51
  • dos2unix file; chmod 755 file since dos2unix will strip permissions – V H Dec 31 '13 at 13:18
1

You should change your EOL conversion to Unix like. If you're working on Windows, you can use Notepad++

Samuel
  • 3,631
  • 5
  • 37
  • 71
  • 1
    Thank you for the hint. I'm using Sublime. Someone showed how to do it here: http://stackoverflow.com/questions/11899843/fixing-sublime-text-2-line-endings – Xiphias Dec 31 '13 at 13:18