Alpha
Alpha
AlphaBeta: when quoting is solved

Architecture Concepts

The Binaries

Introduction

Laravel Bash is mostly other people's programs. Every feature is one of the channels Unix gives every process, and a program that knows how to use it. This page lists them, and why we picked each one over the alternatives.

How Programs Talk

Every Unix process gets the same handful of ways to communicate, and every Laravel concept turns out to be one of them:

ChannelWhat it carriesLaravel Bash uses it for
ArgumentsInput, once, at the startJob arguments, route parameters
Environment variablesConfiguration, inherited by children.env, DB_CONNECTION
stdin / stdoutA stream of textRequests, responses, Eloquent pipelines
stderrDiagnosticsStack traces, the log
Exit codesOne number, 0 to 255Exceptions, validation, failed jobs
SignalsA doorbell with no messageEvents, stopping workers
Files and renamesAnything, durablyQueues, the event log, broadcasts
SocketsBytes between machinesHTTP

The Binaries

BinaryJob in Laravel BashWhy this one
socatThe web servernc has three incompatible versions (OpenBSD, GNU and BusyBox), and Bash's /dev/tcp can connect but can't listen
sqlite3, psqlThe database driversBoth print tab-separated text with -separator and --field-separator
awkwhere, only, the Markdown rendererA whole language for columns of text, in every POSIX system
sortorderBy-t and -k sort by a field; -g sorts numbers; -s keeps ties in order
headtakeIt exits early, and SIGPIPE stops everything upstream
cutpluckThe fastest way to take one column
joinwithCountA real relational join, on sorted text
uniq -cCounting relationsGROUP BY and COUNT(*) in one flag
column -tTinker's tablesLines everything up
jqJSONQuoting JSON by hand is how security advisories are written
mvClaiming jobsA rename is atomic on one filesystem
timeoutJob timeoutsExits with 124, so we know why a job died
flockwithoutOverlapping-n takes the lock or gives up at once
tail -FBroadcastingFollows a file, even after it's rotated
grep --line-bufferedFiltering broadcastsWithout it, events arrive late in 4 KB lumps
pkill, pgrepEvents, HorizonFind processes by their command line
mktempResponse bodies, concurrency resultsUnique files nobody else will write to
sedMigrations, stripping coloursSearch and replace in a stream
shellcheck, batsThe test suiteLarastan and Pest, respectively

Builtins Before Binaries

Starting a program is the expensive part of shell scripting: a fork and an exec cost far more than anything Bash does on its own. So wherever Bash has a builtin that does the job, Laravel Bash uses it:

note

The rule is: use a builtin when one value is involved, and a program when a stream is. sed beats a Bash loop over 10,000 lines. A Bash substitution beats sed on one string.