Builtin function

Home of the ABS programming language: the joy of shell scripting.

Builtin function

There are many builtin functions in ABS. Take type, for example:

type(1) # NUMBER
type([]) # ARRAY

We’ll reveal you a secret now: all string, array, number & hash functions are actually “generic”, but the syntax you see makes you think those are specific to the string, number, etc object.

The trick is very simple; whenever the ABS’ interpreter finds a method call such as object.func(arg) it will actually translate it to func(object, arg).

Don’t believe us? Try with these examples:

map(["1"], int) # [1]
sort([3, 2, 1]) # [1, 2, 3]
len("abc") # 3

At the same time, there are some builtin functions that doesn’t really make sense to call with the method notation, so we’ve kept them in a “special” location in the documentation. exit(99), for example, exits the program with the status code 99, but it would definitely look strange to see something such as 99.exit().

Generic builtin functions


Prints the given variable:

echo("hello world")

You can use use placeholders in your strings:

echo("hello %s", "world")


Reads from the stdin:

echo("What do you like?")
echo("Oh, you like %s!", stdin()) # This line will block until user enters some text

Worth to note that you can read the stdin indefinitely with:

# Will read all input to the
# stdin and output it back
for input in stdin {

# Or from the REPL:for input in stdin { echo((input.int() / 2).str() + "...try again:")  }
5...try again:
2.5...try again:


exit(code [, message])

Exits the script with status code:


You can specify a message that’s going to be outputted right before exiting:

exit(99, "Got problems...")
Got problems...%


Returns a random integer number between 0 and max:

rand(10) # 7


Returns the str environment variable:

env("PATH") # "/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"


Evaluates the str as ABS code:

eval("1 + 1") # 2
eval('object = {"x": 10}; object.x') # 10


Returns the nth argument to the current script:

arg(0) # /usr/bin/abs


Returns the type if the given variable:

type("") # "STRING"
type({}) # "HASH"

cd() or cd(path)

Sets the current working directory to homeDir or the given path in both Linux and Windows.

Note that the path may have a '~/' prefix which will be replaced with 'homeDir/'. Also, in Windows, any '/' path separator will be replaced with '\' and path names are not case-sensitive.

Returns the '/fully/expanded/path' to the new current working directory and path.ok. If path.ok is false, that means there was an error changing directory:

path = cd()
path.ok     # true
path        # /home/user or C:\Users\user

here = pwd()
path = cd("/path/to/nowhere")
path.ok         # false
path            # 'chdir /path/to/nowhere: no such file or directory'
here == pwd()   # true

cd("~/git/abs") # /home/user/git/abs or C:\Users\user\git\abs

cd("..")        # /home/user/git or C:\Users\user\git

cd("/usr/local/bin") # /usr/local/bin

dirs = cd() && `ls`.lines()
len(dirs)   # number of directories in homeDir


Returns the path to the current working directory – equivalent to env("PWD").

If executed from a script this will initially be the directory containing the script.

To change the working directory, see cd().

pwd() # /go/src/github.com/abs-lang/abs


Returns the value of a command-line flag. Both the --flag and -flag form are accepted, and you can specify values with --flag=x as well as --flag x:

$ abs --test --test2 2 --test3=3 --test4 -test5
Hello user, welcome to the ABS programming language!
Type 'quit' when you're done, 'help' if you get lost!
⧐  flag("test")
⧐  flag("test2")
⧐  flag("test3")
⧐  flag("test4")
⧐  flag("test5")
⧐  flag("test6")

If a flag value is not set, it will default to true. The value of a flag that does not exist is NULL.

In all other cases flag(...) returns the literal string value of the flag:

$ abs --number 10
Hello user, welcome to the ABS programming language!
Type 'quit' when you're done, 'help' if you get lost!
⧐  n = flag("number")
⧐  n
⧐  type(n)


Halts the process for as many ms you specified:

sleep(1000) # sleeps for 1 second

source(path_to_file) aka require(path_to_file)

Evaluates the script at path_to_file in the context of the ABS global environment. The results of any expressions in the file become available to other commands in the REPL command line or to other scripts in the current script execution chain.

This is most useful for creating library functions in a script that can be used by many other scripts. Often the library functions are loaded via the ABS Init File ~/.absrc (see ABS Init File).

For example:

$ cat ~/abs/lib/library.abs
# Useful function library ~/abs/lib/library.abs
adder = f(n, i) { n + i }

$ cat ~/.absrc
# ABS init file ~/.absrc

$ abs
Hello user, welcome to the ABS (1.7.0) programming language!
Type 'quit' when you are done, 'help' if you get lost!
⧐ adder(1, 2)

In addition to source file inclusion in scripts, you can also use source() in the interactive REPL to load a script being debugged. When the loaded script completes, the REPL command line will have access to all variables and functions evaluated in the script.

For example:

>>> Testing split and join strings with expanded LFs:
s = split("a\nb\nc", "\n")
[a, b, c]
⧐  s
[a, b, c]

Note well that nested source files must not create a circular inclusion condition. You can configure the intended source file inclusion depth using the ABS_SOURCE_DEPTH OS or ABS environment variables. The default is ABS_SOURCE_DEPTH=10. This will prevent a panic in the ABS interpreter if there is an unintended circular source inclusion.

For example an ABS Init File may contain:


This will limit the source inclusion depth to 15 levels for this source() statement and will also apply to future source() statements until changed.


That’s about it for this section!

You can now head over to read a little bit about errors.