Linux – How to get Linux commands and scripts to work on Cygwin

bashbash-scriptingcommand linecygwin;linux

I'm back with a follow up question. How do I get Linux commands to work on Cygwin? First I asked you what tool should I use to help me run my Linux scripts on Windows and you suggested Cygwin and I installed it plus some packages. Now I am trying some commands which I use in the Linux environment like the iostat, free and ifconfig but they won't work. So my questions are:

  1. Why won't some commands work?
  2. Where should my scripts reside? And should they have an extension of .bat or should I let them keep their extension .sh?

Thanks guys! I really hope you could help me with this one.

Best Answer

Let me clarify terminology first.

  • Linux = operating system kernel
  • Linux distribution = Linux kernel + user-space utilities (bash, ifconfig etc.)
  • Windows = NT kernel + user-space utilities
  • Cygwin = user-space utilities

Because of fundamental differences between NT and Linux kernels you cannot count with your scripts working unmodified on Windows. Some things, which are less specific for OS kernel, work mostly the same way, and Bash is one of them. On the other hand, ifconfig is quite OS-specific and is a part of net-tools project, which hasn't been updated since 2001 and is deprecated since 2004. I believe, there is a cygwin version of ifconfig, and even though it most likely would not work to update configuration, it should work fine to print it. Bryan C. has pointed out how to make sure it is installed.

As for your second question, extension doesn't matter as long as you start your scripts from Bash (it relies on execute permission and shebang line). However, if you want to start them from outside Bash, you'd better make them end with .sh (see this answer for details).

Related Question