loading...

The Windows CLI sucks, and that's good.

tmr232 profile image Tamir Bahar ・4 min read

TL;DR

Windows' shell sucks so people write tools. Tools are fun to use.

Linux's shell is amazing so people write terrible bash scripts and makefiles.

Be sensible. Use Python. Use C.

The rest of the post is me ranting, letting off some steam. Have fun, and don't take it too seriously.

🐚 A Story of Shells 🐚

my_var=$(application arg0 arg1)

for /f %%i in ('application arg0 arg1') do set my_var=%%i

🏭 Windows 🏭

I've been a Windows user for a very long time. In fact, it has always been my main OS. And I absolutely love it. That is not to say, though, that there aren't issues with that. One such thing is the CLI.

For years, the only thing we had on Windows was cmd.exe and .bat files. And they are ghastly. They are pretty straight-forward for very simple things, but try using them for anything more advanced (like setting a variable to the output of a command) and you'll quickly realize that this is not the tool for you. You need a real programming language. So you'll use Python, or C, or something.
It will take you a bit longer to write the tool you needed, but in the process it will become an actual tool and not an annoying script.

In recent years there has been some serious improvements - PowerShell came along, cmder made the shell look a bit better, and I have some Linux tools (grep, awk, xargs...) running in my Windows shell. And yet, people tend to use more general purpose languages on Windows.

🐧 Penguins 🐧

On Linux, however, things have always been good with the shell. It has awesome terminals, and a huge amount of utilities that can be chained (piped) to unleash powers beyond imagination. And unlike Windows, where you need to use funny-looking APIs to get information, Linux just gives you everything in handy text files.

In fact, Linux is optimized for the shell in ways that make me wince. It is actually easier to parse system information (like, say, a process list) in the shell than in C code. Because instead of proper APIs, we have text files. Text files. The kernel takes binary data, formats it into strings, and the user-mode code can then scanf the code back into binary data. Amazing!

But enough of that.

The Linux shell is truly remarkable. You can do pretty much anything in a bash script. And people do.
Now, there's a bit of Linux philosophy that I really like. "Do one thing and do it well." find finds things, grep greps, xargs xargs, and awk awks. So far - so good. But what about bash itself?
While each of the shell utilities does one thing and does it well, bash, and especially bash scripts, do not. They allow you to quickly implement advanced behaviours by hacking together multiple commands. You write more and more and more, and everything just works. And then, it doesn't. And you need to fix it. If you're lucky, and the code is well documented you might get away with that. But more often than not, it won't be. And the wonderful "let's take strings and pass them around" programming style might come back to bite you.

But, again, bash is fantastic for quick hacks. And works fairly well in general when you're not taking input parameters, and when it's small enough. I don't like it, but it works.

🔥 Make Your Own Hell 🔥

The real issue is make.

make is a beast spawned in the deepest dungeons of hell (and I am awfully sorry if I offended any such beast by the comparison.)
Makefiles give you the benefits of never leaving your shell / code-editor while you work. You just create a makefile, define your targets, and you're good to go. In truth - that is fantastic. You can even include bash scripts in your makefiles to do custom steps. Or generate makefiles. Or use automake. Or anything else that might make the task of writing makefiles easier to do and harder to maintain. But you write, and you specify, and it just works! Most of the time.

** Dramatic Pause **

You might have noticed I don't like make. That's true. This post is mainly me complaining about make and blowing off some steam. Now, I appreciate make. I've used it to build things that I never would've managed on Windows. It's an extremely powerful tool. But, you see, as a Windows user, I naturally enjoy IDEs. One such wonderful creation is Visual Studio. As far as C/C++ development tools go it is unparalleled. "But wait!" say my Linux friends, "VS forces you to create foul 'projects' using their fiendish 'GUI'! In Linux, we just write makefiles!"
That is true, and it is quite annoying with small projects (where I usually end up having a .bat file to trigger the build with all the relevant flags,) but it is godsend for anything more complex. You have GUI, and Projects, and Solutions and whatnot. It's great. A bit slow to define, but oh so easy to use!

And now, after I lost most of my Linux-oriented readers, I can get to the point. Linux has a super-powerful shell, so people use it to make a super-powerful mess. Windows has a super-useless shell, so people don't use it. Instead - they build tools! User-friendly(-ish) tools with GUI. And they use general purpose programming languages. And that's good.

📑 Takeaway 📑

Should you stop using bash? Or cripple it? Or keep Windows' shell down? Hell no!

Use whatever tools you deem fit. But use them wisely. Keep shell-scripting to small automation tasks, and try to use more maintainable programming languages when you write something larger or more complex. And do write new tools. Tools are fun.

Discussion

pic
Editor guide
Collapse
jpenuchot profile image
Jules Pénuchot

Use whatever tools you deem fit. But use them wisely.

Can't agree more.

Collapse
ericschillerdev profile image
Unfrozen Caveman Dev

Bless you. Your last few sentences really sum up everything in computing.

Also, as a long time windows user by more or less accident, I'm just happy to see someone writing about it in a way that involves getting things done and shows usage without being fully in the MS stack. I've been doing it that way for years, but I always feel I'm in the minority.

This is what I needed today.

Collapse
tamas profile image
Tamás Szelei

I disagree with the basic statement of the article, i.e. people are forced to implement tools on Windows therefore it's good that the windows shell sucks. No, it's not good, and no, they are not forced to do that. And they don't. I can't tell you how many hours I wasted on debugging organically grown Windows batch scripts. They have terrible syntax and non-intuitive rules that make your head spin. Bad bash scripts are at least understandable and much better to work with.

The biggest sin of make is that it is easy to misuse and that newer techniques of the language have not been popularized enough. A modern and well-written Makefile is nice to work with, but they are few and far between. There are tasks (not only building software) that are very easy to express in make, where a dependency graph with processing is needed. For example, in rpclib I use make to build the documentation: one target calls doxygen, another calls and xslt script that amalgamates the XML output from doxygen, yet another takes that xml and processes it, etc. Changes will only re-run stuff that has to run again. I would have a hard time of implementing that in Python.

But: I do agree that shell scripts (be it windows batch or bash) are not a good fit for many workloads, apart from really small ones. Python is a good choice for replacing them, but this is not because the windows shell sucks.

Collapse
ikirker profile image
Ian Kirker

No one has ever written a quick hack in Python or C! Or VBScript running with WSH!

There are so many things I disagree with in this article, but also, I think it needs to try and make a single argument, or at least maintain a theme, rather than a collection of unrelated thoughts with a sort-of-unrelated title.

Collapse
nonimad profile image
NoNiMad

It is so much easier for me to write one quick hack in Python than in bash. It has everything to manipulate files and other basic actions and is easily readable.
The bash syntax is, while powerful, really not human-friendly. It looks almost nothing like a traditional programming language.

Collapse
zakius profile image
zakius

Be sensible. Use Python. Use C.
to be honest, why would I use C as my goto language? It's pretty absorbing with all the memory management. But still I'd go with that if my only other choice would be Python...

Collapse
dbrower profile image
(((David Brower)))

Dumb question, I'm sure, but with whizzy IDEs (VS, Eclipse, ...), how does one do an automated integration build (daily on schedule, or on-checkin)?

Not a fan of make, but I do like command-line build tools.

Collapse
joelbennett profile image
Joel Bennett

For Visual Studio, I suspect you'd use MSBuild. From what I understand, it's a command line utility for making builds.

Collapse
aadslingerland profile image
Aad Slingerland

Can't agree more. And for windows users/developers etc... take some time to learn POSH (a.k.a. PowerShell). It will take some time to learn but is's awfully good IMHO.

Collapse
bogdangaliceanu profile image
Bogdan Galiceanu

Agreed. A very modern and practical shell

Collapse
rivet92 profile image
Jaime

I've not seen a weirdest argument to defend a crapy tool xDD. But at least i agree with the conclusion.

Collapse
eazel7 profile image
Diego

Those tools will forever be foreigners in the server space. I even prefer Mac people. At least they are posix.