Learning UNIX Bash/Shell scripting on a windows enviornment - bash

I was just curious if there are any tools out there that would allow me to practice shell scripting without dual booting my computer to half windows and half UNIX. I've heard of Cygwin but is that truly UNIX ?

Install Cygwin or install a Linux system under a virtual machine with emulators like VirtualBox.
Cygwin is not completely UNIX but it would be enough with not-too-system related scripting. There are differences though compared to a true UNIX system e.g. process managing wouldn't really work well. /proc too I think doesn't work as expected.

Cygwin is okay, but keep in mind that if you want to learn about UNIX, Cygwin won't help with learning about the Linux filesystem, which is important.

You could also have a look at How to develop in Linux-Like Shell (bash) on Windows?, maybe there are some helpful answers.
Personally, I think a Linux VM is your best option. Cygwin is a UNIX-like environment on top of Windows, it's not a UNIX emulator.

I generally install git with Windows installer. Not only it comes with bash (look for "git bash" in Start menu), it also comes with git (duh) and ssh.
Obviously that's not "truly unix", for that install Virtualbox and in it FreeBSD or some other *BSD (they are officially "unix", unlike Linux which is "just" unix-like).

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!

Scripting language on Windows and Unix

I need to write a script that handle files. Its aim is to open and copy some sections from the file, in a binary context.
The problem is I need to run it on both Windows and Unix.
Is there a scripting language that can handle both operating systems?
Python runs on both. The Windows version doesn't even need cygwin. If you have cygwin, then you can also use bash script.
You can install a scripting language such as Python or Perl and use it on both systems.
Alternatively, install Cygwin on Windows, which will allow you to run a Bash shell under Windows.
Ruby also runs on both systems just fine and has support for manipulating paths for both worlds. There's a nice installer for Windows and most Linux distros also ship it in their default installation.
I've successfully used Tcl across Unix and Windows; you can find more information here and here.
The command shell "bash", native on Unices, is also available on Windows.

Practice Unix on Windows Machine

I want to practice Unix (mostly KornShell (ksh) scripting and VI editor) on a windows Vista machine. What is the best solution for this? I do not like Cygwin. So anything other than Cygwin which gives the closest feel of Unix Environment without re-installing the OS.
Thanks.
You can set up a virtual machine using VMware Player. http://www.vmware.com/products/player/
It lets you run a real *nix environment inside of Windows. It's free, and fairly easy to use.
I think Cygwin is really the easiest way to get what you're asking for, but another option might be MinGW. (Minimalist GNU for Windows).
If you just want to practice with specific command-line utilities, you could also look at: Unxutils.
Like others have said, you could also use a VM to install some type of Unix/Linux OS, like Ubuntu.
Solo es una sugerencia:
Why don't try instaling a virtual machine and then some unix?
Just a little suggestion
Get vim for Windows for vi practice (then get vim for your actual Unix box) and get Cygwin for a shell environment plus Unix utilities.
http://www.elitter.net/
Free shell accounts.
I would say the best way to practice it on your Windows machine is to install a virtual machine (e.g. virtual box, it's free) and set up Linux on that one. Then have them communicate through e.g. a shared folder.
But then there often are Windows clones of many of the most popular software on Unix/Linux systems.
If you want a good alternative to Cygwin, try UWIN.
More information on it can be found here.
I highly suggest that you download a version of unix. Here are some suggestions:
1. OpenBSD
2. NetBSD
3. FreeBSD
After downloading one of these, use virtualbox or vmware and install them in a virtual machine.
1. VirtualBox
2. VMware Player
This way you can easily run UNIX in a virtual environment and practice it easily. It's the most convenient method.
Also if you want you can install arch Linux which is very small and then install ksh shell in it using pacman and then change your default shell from bash to korn by this command chsh -s /bin/ksh. You can do all this in other Linux distributions too. Also if you are only looking for working with shell and vim you can use Ubuntu-server then install KornShell in it as well using sudo apt-get install ksh. It's entirely up to you which option do you wanna take.

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