Java for shell scripting

Ben Weidig
3 min readFeb 20, 2017
Photo by xiaokang Zhang on Unsplash

No matter what your daily driver is, most of us also have to write some shell scripts to automate stuff. Usually, we would use bash script, Python, Perl ,or some other scripting language. But what if we could use a compiled language instead?

One of the significant advantages of shell scripts is that they are just a single file that you can execute easily. Trying to get the same easy usage from a compiled language, I started using Go, which compiles into a single executable that’s runnable without any additional framework or setup on any machine (that is was compiled for). But Java is my daily driver at work, and I’m the only one at the office trying to learn Go it might not be the best choice. After reading Java for Everything I asked myself: “Why not use Java instead?”.

Java for CLI

One of the types of programs Java wouldn’t be the best choice for is definitely CLI compared to many other options. Handling files wasn’t easy/fun until Java 7, no awk, sed, etc., no good/up-to-date curses library available, input handling wasn’t fun either, and no helpful built-in arguments library.

Why would I choose this language for my shell scripts?

Well, because it’s my daily driver, I’m fluent in it, and it has all these great advantages in other use cases: a mature, strong-typed language with a humongous…

--

--

Ben Weidig

Software developer, entrepreneur, blogger. Mostly Java, sometimes Swift, Golang, Bash and all the other fun stuff.