morning folks, have anyone had to setup a linux /...
# general
m
morning folks, have anyone had to setup a linux / unix scripting env in a windows machine ? background: we have a situation, where we need to write multiple scripts to support windows / linux / macOs users is there a way to write one script and use it in all ? other than using
docker
.. your suggestions are invaluable, TIA
c
This really depends on what you need to do. Do you need to user OS specific commands? If not, then good old
make
might be a platform neutral answer. You could even quickly roll a (Go works fine) CLI that is cross-platform compiled.
m
wow! thanks for sharing some pointers.. we have bash script that takes few input params and it uses OS specific commands, we are forced to write a script for each machine that the dev uses.. windows, linux, mac.. could you share some links, when you get time to go and learn about them ?
c
All under the assumption that you’re doing some config work and not providing workflows that the devs should be using continuously.
You can usually share one script between Linux and MacOS - if you need to have GNU compatibility for some commands on MacOS, just homebrew the dependencies in there. You can try to run the same script on WSL (Windows Subsystem for Linux) but if you’re doing things that are OS specific you might be out of luck.
Sorry, but it’s really hard to give concrete pointers without knowing what you try to achieve with that script.
m
I understand, i missed the details, It parses the argument, uses
sed
to replace few texts, and run
npm
commands to install a dependency based on the version stable / beta
c
I would probably just make a
*nix
and a
powershell
version of that script and be done with it. If you want to be really OS agnostic and do things for it anyway, why not use a
node.js
based script in the first place?
m
I see, didn't think of that.. was curious, if there is a way to do
will validate few things you suggested, thank you 🙂
b
What about using python? You could write the platform-independent parts of the script in python and call the external programs in CLI from python. It would simplify the code maintenance, because you have the same code for linux / mac / windows. But it all depends on (1) how many scripts you already have, and (2) how much you could generalize what they are doing (e.g., sed could be reimplemented in python, you could call npm via CLI in python).
m
interesting perspectives and choices 🙂
c
did something like that years ago in Perl so I'd imagine Python could handle it
s
Of course you can use WSL. But if you need closer ties to Windows commands and linux scripts you might find Cygwin a better match.
m
that's new 🤔
s
If the operations can be performed using an OS agnostic or as we say cross-platform programming language, such as "Python" , then instead of using bash, go ahead with such languages for scripting work
s
Lots of ways to do it depending on your toolset/skillset and what's most natural for your project. An example similar to what @Clemens Jütte and @Ben were talking about: Ansible has one goal of enabling admins to write simpler, powerful code which can run in many situations. It's also got a lot of engineering money behind it these days. One
python
version (on the client) can run on most of the *nix like systems (Linux/MacOS/Unix). Windows has an OS architecture and interface that's just too different to throw in the mix effectively. So the Windows client side code is written in
powershell
.
m
wow, Ansible really opened up my eyes https://www.redhat.com/en/ansible-collaborative/how-ansible-works I could understand now, one can take a small task and attempt on these suggestions and learn a lot.. really happy to get these feedbacks
c
Sounds great @Mukundhan Sampath! Let us know what you did choose in the end and how it’s going!
s
You can also try nushell which is cross platform
m
used Makefile and simplified the script, and it works neat.. the code also got simplified So much... thank you for your inputs with the above knowledge, we can say a cross-platform can be said as.. • an executable, either script / an artifact that can be run in a runtime, regardless of the operating system or machine provided the runtime is supported in the machine by default