9

How to remove %0D from end of URL when using wget?

I have a sh script with the following wget. However, when executed on the linux box, wget is attemping the second URL below (%OD attached). How do i prevent this from happening? I have multiple scripts, they're all having the same issue. Thanks!

wget https://example.com/info.repo


wget https://example.com/info.repo%0D
user3388884
  • 4,748
  • 9
  • 25
  • 34

2 Answers2

8

The OD character is a carriage return, part of the CRLF sequence that Windows uses for line endings just to be different as usual.

You can use dos2unix to fix the line endings before executing, and in future don't use Notepad to write shell scripts.

dos2unix myscript.sh
./myscript.sh
James M
  • 18,506
  • 3
  • 48
  • 56
  • No i don't, do i need to install it? – user3388884 Mar 06 '14 at 21:25
  • If you don't already have it then you do. Which Linux distro is this? – James M Mar 06 '14 at 21:26
  • I'm just kidding, I do have it installed. Used it before as well. But for some reason, it isn't working on this file – user3388884 Mar 06 '14 at 21:27
  • It may be a Mac line break (single 0D). Try mac2unix. – Erwin Waterlander Mar 07 '14 at 07:58
  • @ErwinWaterlander OS X just uses `\n`. The single `\r` linebreaks haven't been used since Mac OS Classic. – James M Mar 09 '14 at 12:16
  • I agree with the answer. However, in some situations dos2unix may not be installed nor wanted. It may be easier to convert the file in VIM as noted in [VIM's documentation](https://vim.fandom.com/wiki/File_format). This [SO answer](https://stackoverflow.com/a/82743/886399) provides more details. – Marty Apr 06 '22 at 14:31
  • as per [this answer](https://stackoverflow.com/a/800644/13983021) to a related question, those without `dos2unix` can use `sed` instead – mathlete Apr 05 '23 at 20:11
0

I had this when running wget from a WSL2 instance based on the Windows filesystem (/mnt) instead of the Linux filesystem (\\wsl$\). From WSL2, it in fact is possible to use either.

Running wget to download something into a Windows Filesystem directory under WSL2 gave me this trailing 0%D at the end of the file. I simply started using another working directory under the Linux filesystem, and wget didn't give me this problem anymore.

alelom
  • 2,130
  • 3
  • 26
  • 38