Using mingw/msys just for its posix tools: mount point question - windows

I write cross-platform software, so I like my Windows environment to be Un*x-like (I'm an old Unix/IRIX/Linux geek). I just care about shells and tools, not so much about compilers or the build environment (I have a real industrial-strength build system that doesn't depend on mingw or cygwin). I just want a shell window on my Windows box that works like a POSIX system.
I'd like to move away from cygwin and its CRLF weirdness and dll-dependencies and update troubles, and maybe replace it with mingw/msys. I've started to do this, but am stumped on one thing. I really really need mingw paths to map to the same Windows paths. So / must be c:/ and /windows -> c:/windows and so on. Mingw's default mount setup ends up like a chroot, with mingw "/" mapping to c:/mingw or something like that. You have to use drive prefixes like /c/windows to get to /Windows. I'm happy to tweak my $PATH and whatever else I need to do to make this work. Does anyone have any hints?

You can install Cygwin into C:/, in which case / does become C:/. Dunno whether that can be done with MSYS.
Btw, MSYS is a fork of Cygwin 1.3.3 from 9 years ago, which hasn't seen an awful lot of development compared to Cygwin proper. It has the same approach to line ending issues, allowing both binmode and textmode mounts.

Related

UNIX script to run on WINDOWS

I got a couple of questions,
Is there any way to make a UNIX script run under a windows OS without any add-on like CYGWIN?
Is there any way to transform a UNIX script to a windows batch script, so that i can run it in windows cmd ?
I searched for that but i get referred to the UNIX command win2unix or unix2win , the ones that transform a file from/to windows/UNIX format.
Thanks for the help.
I know you don't want an "add on", but if this may help : you can download MobaXterm (or a portable version of it), which will come with many things, including many unix utilities (shell, etc) and lots you can download from their website.
The portable version is the most convenient (and you can carry it on your usb key, for example)
It's quite slower than cygwin/etc (most commands are emulated via some master binary, and many shell "builtins" becomes instead invocations of that binary, for example), but very portable and neat.
Other solutions (converting, etc) probably will also entail a binary of some sort, so I recommand the above, as it's very portable and gives you a kind of "mini unix inside windows"
Another answer for this old question is to install and run light Unix-like emulators. Here are some options:
MinGW -- native Windows port of the GNU Compiler Collection (GCC)
MSYS -- command line terminal called mintty, bash, version control systems like git and subversion, tools like tar and awk and even build systems like autotools
GitBash -- BASH emulation used to run Git from the command line. *NIX users should feel right at home
The above list installs micro environments much lighter than a typical Cygwin install. Also, in my experience most Bash scripts run on par with native Linux environments in these environments.
Yet another option is installing a Linux Subsytem like WSL2.
Yet another option is converting Bash to DOS by hand or with partial assistance of something like Bash-to-BAT converter, which isn't very full featured, and the Advanced Bash-Scripting Guide.

How to develop in Linux-Like Shell (bash) on Windows?

I'm Windows user. But according to my project requirements, I need to write Linux Shell Script(Bash shell). How to develop Linux Shell on Windows?
Is there any IDE for writing Linux Shell Scripting? Please share me some ideas and resource links.
You have quite a number of options:
cygwin
Install cygwin. It will give you a bash.
mingw
The minimal GNU for windows. Comes with set of commands, compilers. This came with my Git on Windows and now the default shell for small scripts
VM, such as VirtualBox
There are tons on VMs, VirtualBox being easy to use(it powers the Boot2Docker). You can do development and test on real Linux distros.
Ubuntu on Windows 10
There is new kid on the block. This allows you to run User Space Ubuntu using Windows Subsystem for Linux (WSL). see more on it at Microsoft blog
Other notes/IDE support
Shell scripts should be small, requires less IDE etc. I use VIM with syntax highligthing. But it seems ShellED may be useful in your case. I got the link from answer for this question - Bash script plugin for Eclipse?
IntelliJ has couple of plugins too for Bash..
I prefer Gow (Gnu on Windows) over Cygwin. Both will give you bash on Windows, but Cygwin has unnatural conventions for filesystem access (/cygdive/c/some/path instead of c:\some\path).
The native windows command terminal is pretty lame, take a look at Conemu.
I'm not aware of any bash IDE, but there are a plethora of windows text editors with decent syntax highlight for bash scripts. I like Notepad++ and Sublime text (the multiple cursor feature from Sublime rocks!). I don't recommend bash for anything with more than 30 lines, if you ever feel the need for an IDE, perhaps the task is more suited for Python, Ruby or Perl (IMHO Python is more maintainable).
The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).
The Bash shell is coming to Windows. Yes, the real Bash is coming to Windows, said Microsoft's Kevin Gallo at Build 2016 keynote. This is not a VM [Virtual Machine]. This is not cross-compiled tools. This is native."
Here's the steps to run Bash on Windows 10 OS:
Open the Windows Start menu
Type "bash" [hit enter]
Which opens a console running Ubuntu's /bin/bash with full access to all of Ubuntu user space
Yes, you are right, that means apt, set, ssh, rsync, find, ls, grep, awk, sed, sort, xargs, md5sum, gpg, curl, wget, apache, mysql, python, perl, ruby, ruby gem, php, gcc, tar, vim, emacs, diff, patch, nano...and most of the tens of thousands binary packages available in the Ubuntu archives!
Reference
Step-vise Guide to Enable Windows 10’s Ubuntu Bash Shell (Windows Subsystem for Linux)
The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).
Run native Bash on Ubuntu on Windows
Since you need to write linux shell scripts, you are learning Linux. So you should install Linux on your machine (preferably on its own partition and boot from it, otherwise in a VM).
Using cygwin or whatever imitation of Linux shell is not using Linux. You'll learn a lot more by installing and using Linux (and by developing on it with an editor like emacs or gedit or gvim ....). Also, take advantage that Linux is almost entirely free software, so you can study its source code and improve it.
Not installing Linux is not doing yourself a favor.
I believe cygwin is for those who love Linux but have to use Windows. It cannot give you the entire Linux feeling (e.g. you won't be able to write shell scripts looking into /proc which does not exist in Windows, even with cygwin).
If you want to use a simple environment emulating all Linux environment as alternative to cygwin (more lightweight) you can try mingw and you can use notepad++ or emacs or vim to provide some syntax highlight on sh scripts.
Everyone has said to go full Linux or use various mocks.
Cloud9.io is a good option if you don't need that much.
You can set up a "workspace" which can be accessed online, lets you write in literally any language similar to np++, but the best part is, it's an online Linux, so you have a terminal, with all your shell commands - no mock up, no dual boot.
The downside to this is that the free users aren't given that much power, so if you wanted to execute some high-level maths or output a large image, it will crash as you will be using too much memory. But it is still really worth getting into, it's only ever crashed once on me, and I do some pretty memory-intensive things.
There is cygwin , that's a linux console for windows.. so you can execute all the linux command with it.
Install Cygwin to execute the commands. However you can use NotePad++ as editor which has native windows binaries.
http://www.cygwin.com/
http://notepad-plus-plus.org/
For Eclipse Luna Should use this one old version fails on UI error
Help > Install New Software… > Add…
Name: ShellEd
Location: http://sourceforge.net/projects/shelled/files/shelled/update/
I had a similar problem.
I like both Linux and Windows, and I am working on both systems, but for programming (and generally, for text editing) I use Windows, for different reasons. For example, I write C/C++ code on Windows, using the Windows DevC++ IDE, then I can compile this project on Linux, by sharing the files on LAN. Now I have to write long scripts, and I would like to do it in a similar way. Ok, maybe its a special request, but maybe I am not the only one who works in such a mixed environment.
First, I tried notepad++ (it is suggested by others as well), but does it support syntax highlight for Linux scripts? I didn't found this feature...
Then I tried gedit compiled for Windows. It requires the GTK library installed (actually it was already on my Windows). Gedit has syntax highlight for scripts!
So I suggest using gedit for Windows for this case. The edited script can not directly be started/tested with it, but for editing, it is fine!

Is there a way to run Bash scripts on Windows? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have bought and I use Windows 7 Ultimate, and I like to use it to develop applications. One of the down sides (as with every OS) is that I can not run Bash scripts. Is there a way to run Bash scripts on Windows by installing some software? It is ok if it does not work 100%, but as long as the most common functionality is available it should be great.
Install Cygwin, which includes Bash among many other GNU and Unix utilities (without whom its unlikely that bash will be very useful anyway).
Another option is MinGW's MSYS which includes bash and a smaller set of the more important utilities such as awk (you may also want to check the competing fork - Mingw-w64). Personally I would have preferred Cygwin because it includes such heavy lifting tools as Perl and Python which I find I cannot live without, while MSYS skimps on these and assumes you are going to install them yourself.
Updated:
If anyone is interested in this answer and is running MS-Windows 10, please note that MS-Windows 10 has a "Windows Subsystem For Linux" feature which - once enabled - allows you to install a user-mode image of Ubuntu and then run Bash on that. This provides 100% compatibility with Ubuntu for debugging and running Bash scripts, but this setup is completely standalone from Windows and you cannot use Bash scripts to interact with Windows features (such as processes and APIs) except for limited access to files through the DrvFS feature.
Best Option I could find is Git Windows Just install it and then right click on and click "Git Bash Here" this will open a bash window
This will open a bash window like this:
and the linux commands work...
I've tried 'sh' , 'vi' , 'ssh' , 'curl' ,etc... commands
If you're looking for something a little more native, you can use getGnuWin32 to install all of the Unix command line tools that have been ported. That plus winBash gives you most of a working Unix environment. Add console2 for a better terminal emulator and you almost can't tell you're on Windows!
Cygwin is a better toolkit overall, but I have found myself running into surprise problems because of the divide between it and Windows. None of these solutions are as good as a native Linux system though.
You may want to look into using virtualbox to create a linux VM with your distro of choice. Set it up to share a folder with the host os, and you can use a true linux development environment, and share with windows. Just watch out for those EOL markers, they get ya every time.
Best option? Windows 10. Native Bash support!
You can always install Cygwin to run a Unix shell under Windows. I used Cygwin extensively with Window XP.
After installing git-extentions (http://gitextensions.github.io/) you can run .sh file from the command prompt. (No ./script.sh required, just run it like a bat/cmd file)
Or you can run them in a "full" bash environment by using the MinGW Git bash shell.
I am not a great fan of Cygwin (yes I am sure it's really powerful), so running bash scripts on windows without having to install it perfect for me.
In order to run natively, you will likely need to use Cygwin (which I cannot live without when using Windows). So right off the bat, +1 for Cygwin. Anything else would be uncivilized.
HOWEVER, that being said, I have recently begun using a combination of utilities to easily PORT Bash scripts to Windows so that my anti-Linux coworkers can easily run complex tasks that are better handled by GNU utilities.
I can usually port a Bash script to Batch in a very short time by opening the original script in one pane and writing a Batch file in the other pane. The tools that I use are as follows:
UnxUtils (http://sourceforge.net/projects/unxutils/)
Bat2Exe (http://bat2exe.net/)
I prefer UnxUtils to GnuWin32 because of the fact that [someone please correct me if I'm wrong] GnuWin utils normally have to be installed, whereas UnxUtils are standalone binaries that just work out-of-the-box.
However, the CoreUtils do not include some familiar *NIX utilities such as cURL, which is also available for Windows (curl.haxx.se/download.html).
I create a folder for the projects, and always SET PATH=. in the .bat file so that no other commands other than the basic CMD shell commands are referenced (as well as the particular UnxUtils required in the project folder for the Batch script to function as expected).
Then I copy the needed CoreUtils .exe files into the project folder and reference them in the .bat file such as ".\curl.exe -s google.com", etc.
The Bat2Exe program is where the magic happens. Once your Batch file is complete and has been tested successfully, launch Bat2Exe.exe, and specify the path to the project folder. Bat2Exe will then create a Windows binary containing all of the files in that specific folder, and will use the first .bat that it comes across to use as the main executable. You can even include a .ico file to use as the icon for the final .exe file that is generated.
I have tried a few of these type of programs, and many of the generated binaries get flagged as malware, but the Bat2Exe version that I referenced works perfectly and the generated .exe files scan completely clean.
The resulting executable can be run interactively by double-clicking, or run from the command line with parameters, etc., just like a regular Batch file, except you will be able to utilize the functionality of many of the tools that you will normally use in Bash.
I realize this is getting quite long, but if I may digress a bit, I have also written a Batch script that I call PortaBashy that my coworkers can launch from a network share that contains a portable Cygwin installation. It then sets the %PATH% variable to the normal *NIX format (/usr/bin:/usr/sbin:/bin:/sbin), etc. and can either launch into the Bash shell itself or launch the more-powerful and pretty MinTTY terminal emulator.
There are always numerous ways to accomplish what you are trying to set out to do; it's just a matter of combining the right tools for the job, and many times it boils down to personal preference.
There's one more theoretical possibility to do it: professional versions of Windows have built-in POSIX support, so bash could have been compiled for Windows natively.
Pity, but I still haven't found a compiled one myself...

Portable unix-like environment for Windows

I am trying to put together a portable set of files/scripts that will enable me to mimic a unix like environment on Windows.
I do not want to install anything. The setup needs to be able to live on a thumbdrive for example. Currently I am using UnxUtils to provide grep, and more. Im adding these to the Windows PATH environment variable in the current console session by
cd <pathToUnxUtils>
path = %PATH%;%CD%
For Vim (my preferred editor) I am using the "Win32 console executable" (http://www.vim.org/download.php#pc) vim.exe. If I have that in a drive such as \vim\vim73\vim.exe then $VIMRUNTIME is \vim\vim73, which is where my vimrc lives.
I am trying to get some syntax highlighting and indenting going next, which I believe I need to add the appropriate .vim scripts to $VIMRUNTIME\syntax and $VIMRUNTIME\indent
but it does not seem to work.
I am using the console executible instead of something like gVim (which probably does more of what I want "out-of-the-box") because I want to be able to send commands to the same shell using the ! command. gVim does not allow that (correct me if I am wrong)
Lastly, has anyone experienced trouble with "tail" from UnxUtils working on Vista?
I know this probably seems like a stupid way to go about things, but I am really trying to make this work. Id be happy with getting these bits of Unix goodness going on Windows.
Thanks for any help
Check out cygwin portable: http://symbiosoft.net/cygwinportable
Or this guide on how to make regular cygwin run on portable devices: http://sites.google.com/site/devinsezer/Home/software/portable-cygwin
The advantage of cygwin over a thin emulation layer like UnxUtils is that it includes a fully working X11 server so you can even run GUI unix apps if you need to (gitk for example, if you're using git)
I've had some troubles with UnxUtils before re currency - they don't seem to be as up to date as the GnuWin32 stuff (for example, TextUtils at 2.1 instead of 5.3).
I've simply downloaded the executables and required libraries for what I've needed (no install needed if you avoid the setup packages, just copy and go).
If you click on the package names on the left of that second link above (not the "Setup" on the right), it allows you to download both the executable plus all dependencies on a single page.
My particular needs for a recent project were met with sed and about four DLL files, no installation, no impinging on the environment or registry. In short, ideal for running from a memory stick or standalone CD.
I must, at some point, put together a CD with the entire suite on it. I used to carry around CygWin but the necessity to install was a pain.
I'm using MobaXterm from Mobatek.
http://mobaxterm.mobatek.net/
It's not a complete envoirement, but is quite suficcient.
Just download and run!
It have an (ba)sh, with X, sed, grep, awk, rsync, wget, sftp, scp; and some extra plugins (standalone files to put in the same dir) to VIM, EMACS, perl python, Gcc, gdb, mplayer, svn, git, lua graphviz...
It still provides many protocols (RDP, VNC, SSH, telnet, rsh, FTP, SFTP and XDMCP).
Either MSYS or CH will do that, there is a specifically portable VIM at portable apps
Cygwin and MSYS provides all you need. I have used both and I think MSYS runs faster than Cygwin on a Windows machine. Cygwin emulates the UNIX environment whereas MSYS is port of the GNU utils to Windows.
Another option to get portable GNU utils is to install Portable MsysGit.
http://www.cygwin.com/ is very popular.
update: oh, never mind - I don't think it can be xcopy deployed.
-Oisin
I've had good luck with running Cygwin on a thumbdrive. I haven't run it on machines where older versions are installed. But I don't expect to have that problem often.
Here is what I did: http://fadedbluesky.com/2011/portable-cygwin/

Unix-style tools on Windows?

At work (a mostly Unix development shop), I've had an OS X box for the past 1.5 years and a Linux box before that. Due to various circumstances, I'll be getting a Windows XP laptop in the next few weeks. I'm of mixed feelings about this - it's good in that, as a manager, I'm used to running a Windows install (via Parallels) for Excel, Outlook, etc., but it's bad in that I'll miss all of the Unix tools available on OS X.
So, my question to you (community wiki perhaps?) is: What sort of tools would a Unix developer find handy when using a Windows machine? I'd like to be able to do some development on the machine (Perl, mostly), and also easily remote to other (Unix) machines. Here's what I've been recommended so far:
Editor: gvim
SSH: PuTTY
You want cygwin -- and secondarily, for when you absolutely have to work in a CMD.EXE console, unxutils.
Try MinGW, the Minimalist GNU for Windows. Here's a list of GNU tools they offer: http://sourceforge.net/projects/mingw/files/
This includes things like bash, sed, awk, grep, cut, and other familiar GNU tools. Perl is in there as well. I find it a good light-weight alternative to Cygwin.
On windows, you will miss the great GNU/Linux/Unix tools like sed, awk, wget, grep, tr, locate, file, dd, diff,
I wouldn't recommend cygwin though, I prefer native tools.
You can find native ports of the GNU tools at
http://gnuwin32.sourceforge.net/
Then you need a decent syntax highlighter, notepad is just an antique.
Geany is best on Linux, and there is a windows port:
http://www.geany.org/Download/Releases
There is also a windows port of The Gimp, free and opensource, offers the same and more functions as adobe photoshop (but with another interface). It's modest bit more difficult to use, though.
http://gimp-win.sourceforge.net/
For a C/C++/Lisp/Ada compiler and makefiles, you need MinGW, Minimalist GNU for Windows, together with msys (a linux like console).
Unlike cygwin, mingw and msys compile native win applications.
Windows doesn't have Perl installed by default.
You can download a free Perl interpreter from http://www.activestate.com/
Finally, you could install CoLinux, with which you can run Linux apps. on Windows.
CoLinux is hard to install, AFAIK, and you can mess up your computer if you don't know what you do.
If you have Vista Ultimate or XP, you can install SUA/WSU, Windows Services for Unix.
On Vista, it's in the OS Components tab under add/remove software in the control panel
On XP, you must download 300 MB from Microsoft.
Cygwin
Linux-like environment for Windows
making it possible to port software
running on POSIX systems (such as
Linux, BSD, and Unix systems) to
Windows.
Is your laptop good enough to run a VM? That will certainly get you the best of both worlds.
Instead of Cygwin or putty consider MobaXterm and maybe a few plug-ins.
No install needed and it is free; based on Cygwin code.
You just start a single executable file.
It includes the Busybox implementation of vi, sed, awk, wget, and grep, as well as openssh-server, ssh, scp, bash, rsync, X server, {lots more} and you can add things like perl, emacs (why?! :D ) screen, curl or python as plug-ins just by downloading them (versions from the mobaxterm site) into the same directory.
The tools in Busybox are not POSIX complete, but it is a pretty good start out-of-the-box.
It only takes a few minutes to be up & running.
Be sure to set up a persistent home directory and restart mobaxterm so you can keep your ssh keys, bash profile, etc. (ssh-keygen is included...)
You do not need to license it but you get a few extra goodies if you do.
The first thing I do on windows box is to download mobaxterm. I do not use putty anymore unless I have no choice.
main site: http://mobaxterm.mobatek.net/
some plugins: http://mobaxterm.mobatek.net/plugins.html
Just download the 'portable edition' zip file, extract it into a directory, open the executable {NOT the customizer...}, ignore any warnings, set a persistent home [Settings > Configuration > Misc Tab], close the application, restart the application, and then configure to your taste. This way all of your settings will be saved.
Now you can also make another directory to save logs to and turn on logging.
I like leaving 'Paste using right-click' "OFF" (unchecked) because it automatically pastes with a middle-button click anyway, like many terminals. BTW: Highlighting text adds it to your buffer/clipboard automatically.
TIP: try "cd /drives/c/foo/bar" or the like and then search & parse your windows log files with grep, sed & awk ...
DISCLAIMER: I do not work for mobatek or develop mobaxterm but I am a licensed user.
Cygwin gives you Unix command-line tools in a Windows environment.
If the cygwin installation is too heavy-weight for you, and the GnuWin32 installation is too cumbersome (you have to install every tool individually), you can also try out GOW: https://github.com/bmatzelle/gow. The only downside is that the binaries are quite old..
I know I'm late to the party here, however, another great option is Git Bash.
Well, best thing for me is Mobaxterm http://mobaxterm.mobatek.net/features.html
This Cygwin distribution has no installation at all as is one single binary only.
IMHO cmder is better in windows than cygwin to work with unix commands.
Better yet, when you install cygwin select the packages openssh, perl and emacs. Then install ssh daemon using ssh-host-config -y and follow instructions. Now you can ssh to your Windows machine from your Linux box, happily use vi or emacs and develop in Perl, run your perl code, or any other command line Windows exe, or Java or Python, etc. as long as they are console apps (vs a graphical one).
GO for Cygwin.
First install the Cygwin, which gives you a nice unix like terminal. You have lots of additional packages you can install online.
For stuffs like perl and python go for Activestate "http://www.activestate.com/activeperl"
http://www.activestate.com/activepython.
There is also "http://strawberryperl.com/" free, even for commercial usage.
It depends on what you wants:
Cygwin and it’s fork Mingw add Compatibility layer dlls on top of Win32, while SUA/INTERIX run on top of the NT with it’s own subsystem and PE type of executables beneficing many of the things traditionally implemented as *nix syscalls (like fork()) which are available in Native NT but not on WIN32.
So application have a some kind of better support, you can see it here.
Otherwise cygwin is fully supported by red hat which means a lot of binary packages are available while on SUA, the first thing you’ll probably need is to find a way to compile a recent toolchain with the outdated installed one.
I use the Git for Windows "contribute" version, aka msysgit: https://msysgit.github.io/#contribute
This single install includes: MSYS, MinGW, bash, GNU toolkit, gcc, g++, flex, bison, vim, gvim, ssh, git, svn, cvs, perl, tcl/tk, rxvt, etc. It's everything you would need to hack on git, and a good foundation for hacking on anything else.
msysgit takes up 1GB on the disk. (Windows Explorer will tell you it's 3GB, because it doesn't understand hard links.) It builds git from source, and there are a few large git repos.
MSYS+MinGW is lighter than Cygwin. It's better for porting, development, and for general use. It works both in the windows CMD prompt and in an rxvt terminal.
There is also MSYS2, I haven't tried it yet but I hear it is more up to date than msys or msysgit. See also: How are msys, msys2, and msysgit related to each other?
You can also try 'Install Windows Subsystem for Linux' in Win10. Link

Resources