How to run Linux shell script on windows environment

15,107

Solution 1

It depends on how complex the scripts are, whether you want to make changes to them and what utilities the existing ones use.

If the scripts are very complex, you will be better off keeping the original and use Cygwin.

If you want to maintain the scripts and port changes back and forth, you will want to use the original (and use Cygwin)

If the script uses some Unix utilities that have not been ported to Cygwin, you either need to do the porting yourself (to be able to keep the original scripts) or convert the scripts to use Windows equivalent (or similar) programs

So I'd recommend you using Cygwin in most cases, unless the scripts are very easy to translate to Windows batch format

Solution 2

As stated in comment, I'd like to see or know what the script does. Under windows there are a couple of options for scripting now. (Powershell, vbscript, javascript, plain old batch files), but really it depends on what the original script does.

IMHO is just plain overkill installing the whole cygwin or a bash porting just for moving files or performing other trivial tasks.

Solution 3

I would recommend option 3 and it is the only way to run the same script (assuming script = bash script) under windows.

Solution 4

4: Install a port of BASH for windows, e.g. win-bash
5: Use SUA/SFU, see this link

Solution 5

You can try colinux

http://www.colinux.org/

Cooperative Linux is the first working free and open source method for optimally running Linux on Microsoft Windows natively. More generally, Cooperative Linux (short-named coLinux) is a port of the Linux kernel that allows it to run cooperatively alongside another operating system on a single machine.

Share:
15,107
KItis
Author by

KItis

software engineer

Updated on June 04, 2022

Comments

  • KItis
    KItis almost 2 years

    I have housekeeping script which is running on Redhat operating system.

    I have a requirement where i want to run the same script in the Windows environment.

    So i have 3 options

    1. Write a new script for windows
    2. Convert Linux script in to windows script using some tool.
    3. Use Cygwin and run the script without making any change to the linux script.

    So i want to know what would be the best option to select.

    Thanks in advance for any help

    • BigMike
      BigMike about 12 years
      it depends on what the script does... windows batch are not powerfull as shell-script. of course you can use javascript or powershell if you have knowledge of them.
    • KItis
      KItis about 12 years
      using java-script or power shell meanings going for option 1 right?
    • BigMike
      BigMike about 12 years
      exactly, but using the right tools for the right task can help. Take a look at robocopy, is easy to use it in simple .cmd / .bat and may just solve your whole problem with just a oneline.
    • sorpigal
      sorpigal about 12 years
      It's impossible to say what the correct approach is without some details about the script, preferably seeing it in its entirety. What commands do you rely on? Of those, which are standard tools and which are RH-specific? Do you touch any files and how do you reference the file paths? All of these questions would need to be answered.
  • KItis
    KItis about 12 years
    when i select that option, i need to run the script as a cronjob, so how do i do that with cygwin. do you have answer to that. cronjob is not available in cygwin
  • c2h2
    c2h2 about 12 years
  • KItis
    KItis about 12 years
    original script is a housekeeping script for deleting old log files and archiving log files which are older than given time period
  • BigMike
    BigMike about 12 years
    the answer to your needs can be robocopy (a good utility that manages file copies).