0

I am using WSL2 Ubuntu with Windows. I have an alias opening Notepad++ on Windows defined inside WSL like this:

alias npp="/mnt/c/Program\ Files/Notepad++/notepad++.exe"

and it works... but as soon as I add another alias, e.g.

alias npp="/mnt/c/Program\ Files/Notepad++/notepad++.exe"
alias l="ls -l"

I get the error - : No such file or directory/Notepad++/notepad++.exe. It works only when it is the last alias defined in the file.

My guess is it might have something to do with a space in the Notepad++ path but I am not really sure anymore. I tried different ways of escaping with no luck. What is happening here, what's the cause and the fix?

micper
  • 169
  • 12
  • Where are you defining those aliases, and is there any chance you are editing the file with Notepad++? I'm thinking it could be a line-ending problem. – NotTheDr01ds Jan 21 '21 at 21:19
  • 3
    **You have a CR character in your file.** The alias value you've set is actually `/mnt/c/....notepad++.exe` and that is a filename that does not exist. Edit the file with an editor that can remove the CR, or use dos2unix if included in the distro/instance you are using. – dave_thompson_085 Jan 21 '21 at 21:20
  • 1
    In addition, the definition of `npp` was probably the *last* line of the file, which didn't end in CRLF until you added an additional line. `bash` expects a POSIX text file: one in which *every* line is terminated with a linefeed; the CR of the CRLF pair is treated like any other character. – chepner Jan 21 '21 at 21:30
  • True that! I am editing unix system files mostly with nano however it might have happened I opened aliases file with Notepad++ once :) Thank you. – micper Jan 21 '21 at 21:32

1 Answers1

1

I can reproduce if I edit a script with those aliases using Notepad++ and leave the line endings as "Windows". If you want to use Notepad++ to edit your bash scripts, make sure to use Edit -> EOL Conversion -> Unix (LF) before saving.

After doing that, the alias script works correctly for me.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70