I have a bat script that I'd like to make work on windows/Mac/linux, but I read .bat is only for windows. How can I make this script work on Mac and linux, or what type of script can I write that would work on all 3.
If you don't want to step up to a language like C, I would suggest Python as a multi-platform scripting language. It's easy to learn and has lots of generic, multi-platform libraries and functions.
You'll need to install it on Windows, and maybe OS X as well. But it's not difficult in any way.
py2exe
so the user wouldn't have to install the python runtime. –
Eran No such beast. Windows doesn't support the unix-style shell scripts that Mac/Linux use, and Mac/Linux don't have command.com/cmd.exe needed to support .bat files.
There's ways to fake this, like running Wine on mac/linux and cygwin on Windows, but then that's a whole other ball of wax.
If you don't want to step up to a language like C, I would suggest Python as a multi-platform scripting language. It's easy to learn and has lots of generic, multi-platform libraries and functions.
You'll need to install it on Windows, and maybe OS X as well. But it's not difficult in any way.
py2exe
so the user wouldn't have to install the python runtime. –
Eran - Python
- Bash + MSYS on Windows
- Groovy / Beanshell / Javascript ... with corresponding interpreter
There isn't one shell scripting language that is available on all three without installing something on one of the platforms. And in the case of Windows, installing something like Bash
which is available on Linux and OSX, is less than useful as it never will integrate with Windows as seemlessly as it doesn on OSX and Linux, and never be able to do everything as integrated as a .bat or PowerShell file will be able to.
Personally when I need cross platform scripting I reach for Python.
useless
I said less than useful
. I have adding clarification on why that is. –
Sabaean .bat scripts are only going to work on windows. I would keep the bat script that you have for windows and create a bash script designed to work on linux and osx.
Please don't make me install the cygwin tools just to run a script.
you can write a batch-file and let it interpret from cmd on windows and sh on linux
but there is not much syntax in common, so you will be forced to run os-specific scripts from that point
If you're comfortable with JavaScript, you could install Node.js on each platform, then write a command line tool and run like so:
> npm install yourtool-cli -g
> yourtool [args]
N.B. it's common to add suffix -cli
to your command line node package name. The -g
option is to install globally rather than in the local folder.
The File System module lets you do a lot of stuff that batch/script files do, for example.
You can install Powershell on Mac. In this case, you can write your ps1
files and execute them in Windows and Mac
© 2022 - 2025 — McMap. All rights reserved.