0

Is there a tool which translates windows batch to bash files and visa versa?

Jan Viehweger
  • 522
  • 5
  • 19
  • 1
    Why not use a language that exists on all platforms? Python, Perl, etc. – choroba Feb 21 '17 at 08:55
  • as far as i know these language are not installed on a users computer by default - at least on windows. I'm developing a cross browser standalone app which need's to run several shell commands. – Jan Viehweger Feb 21 '17 at 10:31
  • @JanViehweger: I wouldn't assume *any* language to be installed **by default** on Windows, unless you count Windows Batch Scripts as a language. You might reasonably assume that JVM is available everywhere, so you can use any language which produces Java Bytecode - Ruby, Python, Scala, even Java. Another possibility is to compile to machine code, so you have one common source, but need to compile for each target platform. The last possibility would be a language where an implementation exists which can be easily distributed with your source code (for instance gawk or bash). – user1934428 Feb 21 '17 at 12:46
  • 1
    I would write my script in node.js / JavaScript. It is pretty portable. – Rolf May 10 '19 at 14:09
  • fwiw https://github.com/batsh-dev-team/Batsh compiles to bash or batch – Brian Burns Jun 04 '21 at 20:58

2 Answers2

2

Yes, cross-platform coding is possible.

cross-platform scripting for windows, Linux, MacOS X

PowerShell is cross-platform (Windows, Linux, Mac):

See these links (yes, I know links are generally frowned upon, but this is a very general question!)

https://www.google.co.uk/search?q=powershell+cross+platform+scripting

cross-platform scripting for windows, Linux, MacOS X

https://blogs.msdn.microsoft.com/dotnet/2016/08/18/powershell-is-now-open-source-and-cross-platform/

https://blogs.msdn.microsoft.com/scxplat/2009/12/11/cross-platform-powershell-scripts-released/

https://github.com/PowerShell/PowerShell

Perl is also cross platform

How to write cross-platform perl code

Python can be, as long as no OS-specific libraries are used.

Community
  • 1
  • 1
TechSpud
  • 3,418
  • 1
  • 27
  • 35
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/15285107) – SOFe Feb 21 '17 at 09:28
  • Agreed, @PEMapModder, but as mentioned, the question is vague. Some of the links are to SO itself. I guess I'm not expected to actually write cross-platform scripts? – TechSpud Feb 21 '17 at 09:30
  • If the question is too vague or duplicates other questions on SO, flag the question as duplicate or "too broad". – SOFe Feb 21 '17 at 09:36
  • Cool. Have flagged. Thanks @PEMapModder – TechSpud Feb 21 '17 at 09:37
  • @TechSpud thanks for the links! https://github.com/BYVoid/Batsh is exactly what i was looking for. – Jan Viehweger Feb 21 '17 at 10:34
  • No problem, @JanViehweger – TechSpud Feb 21 '17 at 10:35
0

For some standard operations it is an easy task because some commands do the same job (e.g. more and less, cd, ipconfig and ifconfig, md and mkdir, ...). So for a basic prototype you just have to replace some commands.

But the majority of commands differs a lot regarding parameters etc. So it won't be a hard job, but a very time consuming one to look at every shell command including allowed parameters and expected parameter values and to "translate" them to the appropriate form for another OS.

I think that there are two main options for your task:

  1. install bash on Windows10 (if you already switched to it) which offers you a basic bash shell so you can use linux commands on windows
  2. use powershell and install it on Mac and Linux as well

Another option is to use interpreted programming languages which can run on both platforms (e.g. Perl or Python can do that job quite good)

user3932876
  • 247
  • 2
  • 11