Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmder corrupts %PATH% if there is exclamation mark in it #1678

Closed
brkerez opened this issue Mar 1, 2018 · 14 comments · Fixed by #2194
Closed

Cmder corrupts %PATH% if there is exclamation mark in it #1678

brkerez opened this issue Mar 1, 2018 · 14 comments · Fixed by #2194
Labels
👀 Awaiting Response Waiting to hear back from the issue reporter.

Comments

@brkerez
Copy link

brkerez commented Mar 1, 2018

I noticed that when my user PATH environment variable contains some entry with !, next entry gets corrupted thus executables there are not found then when running from Cmder while they are reachable from classic cmd.

Don't know if that's Conemu or Cmder problem, but it seems that when parsing PATH, characters following ! till next semicolon (inclusive) get eaten, missing semicolon then causes that next entry is concatenated with preceding broken part and both ends up corrupted and executables are missing from PATH in Cmder.

Similar, maybe related open issues #1589 , #1650

Example

user PATH in cmd (notice the entry c:\Users\501554096\!appdata; and following entry with c:\Users\501554096\work\scriptsDeploy\;):

Path=C:\development\Ruby25-x64\bin;C:\ProgramData\Oracle\Java\javapath;C:\development\Python27\;C:\development\Python27\Scripts;C:\Oracle\product\11.2.0\client_2\bin;c:\Oracle\instantclient21\;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CA\DSM\bin;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\PuTTY\;C:\Program Files\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\GitExtensions\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\TortoiseGit\bin;c:\Users\501554096\!appdata\;c:\Users\501554096\work\scriptsDeploy\;c:\Program Files (x86)\PuTTY\;c:\development\gradle4\bin;c:\development\jarscan\;c:\development\ant\bin\;c:\development\maven\bin\;C:\Users\501554096\AppData\Local\atom\bin;c:\Users\501554096\apps\wget\

PATH in cmder (!appdata; gone, both entries combined into c:\Users\501554096\\Users\501554096\work\scriptsDeploy\;):

Path=C:\Users\501554096\apps\cmder\bin;C:\Users\501554096\apps\cmder\vendor\conemu-maximus5\ConEmu\Scripts;C:\Users\501554096\apps\cmder\vendor\conemu-maximus5;C:\Users\501554096\apps\cmder\vendor\conemu-maximus5\ConEmu;C:\development\Ruby25-x64\bin;C:\ProgramData\Oracle\Java\javapath;C:\development\Python27\;C:\development\Python27\Scripts;C:\Oracle\product\11.2.0\client_2\bin;c:\Oracle\instantclient21\;;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CA\DSM\bin;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\PuTTY\;C:\Program Files\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\GitExtensions\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\TortoiseGit\bin;c:\Users\501554096\\Users\501554096\work\scriptsDeploy\;c:\Program Files (x86)\PuTTY\;c:\development\gradle4\bin;c:\development\jarscan\;c:\development\ant\bin\;c:\development\gource\;c:\development\maven\bin\;C:\Users\501554096\AppData\Local\atom\bin;c:\Users\501554096\apps\wget\;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\share\vim\vim74;C:\Users\501554096\apps\cmder\

Version

cmder: v1.3.5
os: Windows 7 x64

@daxgames
Copy link
Member

daxgames commented May 12, 2019

@brkerez - Sorry for the horribly delayed response but is this still an issue with current unrelease version?

@xuzanxu
Copy link

xuzanxu commented May 30, 2019

@daxgames still broken, make a directory called "!" and extract cmder into it, vendor/init.bat won't run properly

@stale stale bot added the 👀 Awaiting Response Waiting to hear back from the issue reporter. label Jun 29, 2019
@stale stale bot closed this as completed Jul 6, 2019
@mulle-nat
Copy link

mulle-nat commented Oct 11, 2019

I just wanted to ressurrect this bug, since I ran into it. Or should I open a new one ?

@daxgames
Copy link
Member

! is a special character in bash shell and in cmd.exe. probably not a good idea to creat folders with ! in the and definitly not put them in wnvitonment variables.

@mulle-nat
Copy link

It's maybe not a good idea, yet cmnder shouldn't mangle them. cmd.exe deals with them OK and can also use the %PATH%. A user may well be named "Hello!" and then you have it all over the place.

@daxgames
Copy link
Member

daxgames commented Oct 12, 2019

! Expansion is configurable in clink. I think you can disable it completely which is what you are asking for. I just cant remember the exact setting. Cmder is trying to make cmd more like bash by providing this functuonlity as a default.

The majority of people would not have directories with special characters in them as evidenced by the fact that this issue went stale and was closed automatically. We are reluctant to change long standing defaults without overwhelming request to do so.

@mulle-nat
Copy link

I don't know clink, so I can't comment on it. Only on bash. Interpreting '!' in environment variables strikes me as a bad idea irregardless. Again: cmd.exe doesn't mind and works with '!'. Why is clink
authorative and not cmd.exe ?

bash certainly doesn't do it. e.g. foo='x!x'; eval echo "$foo" -> x!x. '!' in bash AFAIK is just a repl feature.

@daxgames
Copy link
Member

OK @mulle-nat I did some looking at this. Sorry was in the car earlier responding via my phone. The reason this is failing is because %cmder_root%\vendor\init.bat, Cmder's init script, uses a cmd.exe extension called delayedexpansion to do some advanced env var operations.

Delayed expansion wraps env vars with ! instead of %. Env vars wrapped in ! in if or loop operations are not expanded until the script hits that line. Without delayed expansion Cmder would not be be able to initialize itself.

Your directory has one ! and delayedexpansion expects them to come in pairs so when Cmder's init.bat runs it sees it as an opening marker for a delayedexpansion env variable and when it doesn't find a closing one everything after that is messed up.

delayedexpansion is a feature of Cmd.exe and is the reason you should not use ! in any component that could be used in a *.bat or *.cmd script.

Again don't use special characters like ! in directory names. You would have the same issue running a script that used delayedexpansion in cmd.exe that had nothing to do with Cmder.

@daxgames daxgames added wontfix and removed wontfix labels Oct 12, 2019
@mulle-nat
Copy link

I just read this https://ss64.com/nt/delayedexpansion.html and hey, what a crap feature that is. But anyway, I don't know that much about BAT files. I looked at init.bat. Maybe this helps and maybe it doesn't. It seems that you are "enhancing" the PATH with some stuff. If thats true, you could

  • save the old PATH
  • wipe the PATH
  • turn on delayedexpansion
  • enhance a clean PATH
  • turn off delayedexpansion
  • prepend old PATH to new PATH

@daxgames
Copy link
Member

I am trying to help you by continuing to looking at this, not having much luck though. Cmd.exe is a crap shell that does a lot of bad stuff so these extensions were developed. The entire reason Cmder exists to try and make more usable. This is a very rare situation.

If you can''t not have an ! in the path then why not just use bash with is afar superior shell anyway.?

@mulle-nat
Copy link

My current workaround is, that I moved the corrupted PATH parts to the end of the definitions. But this will bite me in the future again I'm sure.

I could probably just remove the code from vendor\init.bar or throw all the init code away. Personally I don't need all the nice stuff Cmder offers in the init scripts.

I am running bash inside Cmder :). My setup is, that I run the Visual Studio command line shell, to get the environment variables. Then I start Cmder from within, to get a more sane terminal. And then inside Cmder I am starting WSL and then I am in a bash.

But corrupting the PATH is still wrong IMO, so thats why am writing this.

@daxgames
Copy link
Member

Using ! in directories in the path is what is wrong. Try this though. It works for me.

@mulle-nat
Copy link

You say that it's wrong, but actually the list of characters, that are illegal for a directory name does not contain '!' https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file. It's not illegal on Unix either, just inconvenient. I will try your artifact and report.

@mulle-nat
Copy link

Looks good to me now.

@cmderdev cmderdev deleted a comment from stale bot May 28, 2024
@cmderdev cmderdev deleted a comment from stale bot May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 Awaiting Response Waiting to hear back from the issue reporter.
Projects
None yet
4 participants