1

I created Shell Script on Linux and it runs fine.

Now I want to run the same script on Windows using gitbash. (Only filepath changed for windows)

I am confused:

  • do I need to write a new shell script again according to Windows syntax shell script?

or

  • can a Linux syntax shell script run on Windows without changes?

According TO differences-between-windows-batch-and-linux-bash-shell-script-syntax

4
  • You can run bash on windows, as well as some other UNIX shells (ash, tcsh) ... However, there are many minor problems you may encounter, as Windows & UNIX are very different ... If you want to make something cross-platform, I advise using Python, Java, Ruby, or some other language better suited for this job. Commented Jan 9, 2015 at 10:45
  • if you wrote a Shell script, you can run it in Windows using cygwin. Commented Jan 9, 2015 at 10:45
  • 1
    Here download cygwin Commented Jan 9, 2015 at 10:46
  • @fedorqui in my learning 'cygwin' And 'gitbash' do same stuff for windows Commented Jan 9, 2015 at 10:47

2 Answers 2

3

Of course you can. There is a tool called cygwin that allows you to do so.

Note that you have to check what the paths are. If so, go to the path you are willing to work on and do pwd. This way, you will get the Windows\kind\of\path.

I use it all the time and it works pretty fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Changing slash for windows environment got my script working And Used cygwin
2

You can use Git Bash

It depends on how advanced the scripts are, but simple scripts can be executed in Git Bash.

test.sh contains:

#!/bin/bash
echo Hello World!

Execute script:

./test.sh

Output:

Hello World!

Git Bash vs Cygwin

To answer your question:

@fedorqui in my learning 'cygwin' And 'gitbash' do same stuff for windows

Git Bash

Git Bash is lightweight and only aims to handle:

  • version control
  • a shell that runs commands

Read more: http://openhatch.org/missions/windows-setup/install-git-bash

Cygwin

  • a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
  • a DLL (cygwin1.dll) which provides substantial POSIX API functionality.

Read more: https://www.cygwin.com/

1 Comment

thanks for teaching Cygwin for Complex scripts is more better than gitbash for simple scripts.As Cygwin brings bigger part of linux environment in windows.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.