1

I'm trying to upload and download a bash script from pastebin, upload was straightforward enough with copy and paste, download didn't go as easy.

There are two scripts I'm trying to download, these are the commands:

wget http://pastebin.com/raw.php?i=M6iQ6RaY --output-document=ts3update
wget http://pastebin.com/raw/e11R2wkP --output-document=ts3restore

When I try to run them, I get this error:

./ts3update: /bin/bash^M: bad interpreter: No such file or directory

Then if I remove the interpreter line, I just get this:

./ts3update: line 4: $'\r': command not found

And this:

./ts3restore: line 3: $'\r': command not found
./ts3restore: line 7: syntax error near unexpected token `$'in\r''
'/ts3restore: line 7: `        case $yn in

Why does this happen, and how can I fix it? When I read or grep the files I find no instances of ^M or '\r' why does bash see something like that when nothing else does?

Cestarian
  • 2,051
  • Your downloaded file has Windows CRLF line endings (^M is carriage return). Use dos2unix ts3restore. – Michael Homer Mar 02 '16 at 03:46
  • @MichaelHomer not really a duplicate, while the solution may be the same, the issue is different; e.g. if this gets deleted because of that, other users may just repeat my question. Anyhow, the best answer was in there (the sed one), i'll go ahead and post it. Thanks. – Cestarian Mar 02 '16 at 03:53
  • no, really, it is a duplicate. It doesn't matter how the script got windows CRLF line-endings (there is an enormous number of ways that could happen, and it would be absurd to treat them all as completely different problems rather than as minor/irrelevant variations of the same problem), the fact is that it has them, and the problem is the same - /bin/bash^M does not exist, so can not be used as an interpreter to run the script. The solution is also the same - convert to unix style LF-only line-endings. – cas Mar 02 '16 at 04:39
  • @cas Hmm I guess so. – Cestarian Mar 02 '16 at 05:11

1 Answers1

1

The answer as Michael Homer pointed out is that pastebin has added Windows CRLF line endings to my files. To fix it I ran the following:

sed -i 's/\r$//' ts3update
sed -i 's/\r$//' ts3restore

And the scripts executed successfully. The answer was taken from here: Bash/Korn shell script edited on Windows throws error '...^M: not found'

Cestarian
  • 2,051