0

I have this useful batch script named lxss.cmd added to my PATH:

::@ECHO OFF
@ECHO ON
set arg1=%*
"C:\Windows\System32\bash.exe" -c "%arg1%"

Which is outputting:

User@LANTI-DESKTOP C:\Users\User
$ lxss lsb_release -a && uname -a

User@LANTI-DESKTOP C:\Users\User
$ set arg1=lsb_release -a

User@LANTI-DESKTOP C:\Users\User
$ "C:\Windows\System32\bash.exe" -c "lsb_release -a"
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial
MSYS_NT-10.0 LANTI-DESKTOP 2.6.1(0.305/5/3) 2017-01-25 00:01 x86_64 Msys

As you can see, the uname -a command left from this execution, but instead run by MSYS2 which is also presented in my PATH. Probably the && command also handled by MSYS2. But this won't be a problem if set arg1=lsb_release -a line would be containing && uname -a also.

My expected output that I want to achieve:

User@LANTI-DESKTOP C:\Users\User
$ "C:\Windows\System32\bash.exe" -c "lsb_release -a && uname -a"
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial
Linux LANTI-DESKTOP 3.4.0+ #1 PREEMPT Thu Aug 1 17:06:05 CST 2013 x86_64 x86_64 x86_64 GNU/Linux

I found the %* variable here, but looks like && terminating the readout. Is there a way to achieve what I want?

Edit:

As reading here the Windows and Linux && command basically doing the same thing.

So I edited slightly my script: "C:\Windows\System32\bash.exe" -c %*

And now I executing with this command: lxss "lsb_release -a && uname -a"

Which is works, but would be much nicer with less typing and look as linux like as possible. Any ideas?

Community
  • 1
  • 1
Lanti
  • 2,299
  • 2
  • 36
  • 69
  • 2
    The problem is that `&&` is a consitional command separator, which needs to be in between quotation marks or escaped like `^&^&` in order not to be recognised by the parser and therefore not to be executed. You need to show how you provide the arguments... – aschipfl Jan 25 '17 at 22:20
  • It's in the first commandline, this is what I enter to execute: `$ lxss lsb_release -a && uname -a`. Somehow not possible to write a regex to always replace `&&` with `^&^&` for `arg1`? – Lanti Jan 25 '17 at 22:22
  • The batch file is executed by `cmd`, the Windows command processor, which consumes the `&&` on its own. Why are you trying to use the batch fie after all? – aschipfl Jan 25 '17 at 22:41
  • I tried to save so much typing as much as I can, but looks like I need to deal with the commas. Because other `bash`es presented in my PATH, I include the full directory for `bash.exe`, which I not want to type every time, plus I want to replace `clang` and `clang-format` for Sublime Text from MSYS2 by the LXSS equivalent ones. – Lanti Jan 25 '17 at 22:45

0 Answers0