Bash Toys

Introduction

For the sake of triviality and pointless uniquity, this page provides a collection of snippets that are syntactically correct but look unique, odd and often have no apparent useful purpose whatsoever.

This page exists purely for academic purposes. Do not use code like this in shell scripts.

Feel free to add your own.

Innocent

Add snippets here that are innocent, entertaining or just do nothing at all.

Pointless exercise in operators

The following burp of bash operators defines a function named _ which truncates a temporary pipe which contains the output of the no-op : command that yields no output; and then runs it. The result: Nothing whatsoever.

_(){ > >(:);};_

Risky

Add snippets here that may be intrusive, dangerous or damaging when executed.

Do not run any of these snippets in your shell without fully understanding them, solely at your own risk!

And don't act like a 12 year old by passing these snippets to ignorant or unwitting people either.

Recursive exercise in operators

This creates a function named _ which truncates the temporary pipe that bash creates to contain the output of a new execution of the same function. The result is a recursively executing bash function. Since the recursion happens through an asynchronous process (which is how >(..) works), this one is slightly annoying to stop. Not quite as paralyzing as the Fork Bomb, though.

_(){ > >(_);};_

Fork Bomb

What this does is create a function named : which calls itself recursively. Twice. In the background. Since the function keeps calling itself over and over (forking new processes), forever, this quickly consumes a lot of system resources. This can be very destructive for a system where no resource limits are in effect.

:(){ :|:&};: