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

3

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
Vrablik answered 6/3, 2014 at 21:18 Comment(0)
C
9

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
Concertina answered 6/3, 2014 at 21:21 Comment(7)
No i don't, do i need to install it?Vrablik
If you don't already have it then you do. Which Linux distro is this?Concertina
I'm just kidding, I do have it installed. Used it before as well. But for some reason, it isn't working on this fileVrablik
It may be a Mac line break (single 0D). Try mac2unix.Ornas
@ErwinWaterlander OS X just uses \n. The single \r linebreaks haven't been used since Mac OS Classic.Concertina
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. This SO answer provides more details.Speciosity
as per this answer to a related question, those without dos2unix can use sed insteadMalleolus
S
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.

Stomato answered 10/3, 2023 at 14:10 Comment(0)
D
0

If dos2unix is not an option (e.g. cygwin) you can open the file in notepad++, Edit->EOL Conversion -> Unix (LF)

Dreary answered 16/3 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.