Introducing ABS, a programming language for shell scripting

Read on!ExamplesI’m a firm believer in the “show me the code!” mantra, so let’s quickly get to it.

Running shell commands is extremely easy in ABS:# Get the content of your hostfile$(cat /etc/hosts)and pipes work too:# Check if a domain is in your hostfile$(cat /etc/hosts | grep domain.

com | wc -l)At this point we can just capture the output of our command and script over it:# Check if a domain is in your hostfilematches = $(cat /etc/hosts | grep domain.

com | wc -l)# If so, print an awesome stringif matches.

int() > 0 { echo("We got ya!")}It won’t happen, but let’s say that an error happens:# Check if a domain is in your hostfilematches = $(cat /etc/hosts | grep domain.

com | wc -l)if !matches.

ok { echo("How do you even.

")}# If so, print an awesome stringif matches.

int() > 0 { echo("We got ya!")}We could make this a bit more general:$ cat script.

abs# Usage $ abs script.

abs domain.

com# Check if a domain is in your hostfiledomain = arg(2)matches = $(cat /etc/hosts | grep $domain | wc -l)if !matches.

ok { echo("How do you even.

")}# If so, print an awesome stringif matches.

int() > 0 { echo("We got %s!", domain)}Now, strings are fairly boring, so we can try something more fun:# Say we're getting some JSON from a commandx = $(echo '{"some": {"dope": "json"}}')x.

json().

some.

dope # "json"# Arrays, you say?tz = $(cat /etc/timezone) # "Asia/Dubai"parts = tz.

split("/") # ["Asia", "Dubai"]# You better destructure the hell out of that![continent, city] = tz.

split("/")…and so on.

There are loads of “regular” things you can do with ABS, so I won’t focus much on those — let me show you the weirder parts instead:# Avoiding the bug that happened because# we forgot to compare strings case-insensitively"HELLO" ~ "hello" # true# Just range1.

3 # [1, 2, 3]# Combined comparison operator (thanks Ruby!)5 <=> 5 # 05 <=> 6 # -16 <=> 5 # 1# Classic short-circuiting1 && 2 # 21 || 2 # 1You can skim through the whole documentation within 15 minutes: ABS’ aim is not to be a general-purpose, feature-loaded language, so the surface isn’t that wide.

In addition, if you’ve worked with languages such as JavaScript, Python or Ruby you won’t have troubles getting used to ABS.

What’s going to happen now?You can head over to ABS’ website, and learn more about the language.

The brave ones will instead make a trip to ABS’s github repo and download a release to install it locally.

The braver ones will just:sh <(curl https://www.

abs-lang.

org/installer.

sh)(you might need to sudo right before that)Which one will you be?Photo by Fabian Grohs on UnsplashOriginally published at odino.

org (25th December 2018).

You can follow me on Twitter — rants are welcome!.????.. More details

Leave a Reply