Larger Script Organization
Script Layout
Pick a Shape
As scripts grow, project layout matters. A single-file script can stay small, while a project layout separates entry points, helpers, and tests.
Program
Play the script to choose the layout and see the planned entry point and directories.
script_layout_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
layout="small"
if [ "$layout" = "project" ]; then
entry="bin/deploy"
dirs="bin lib test"
else
entry="./deploy.sh"
dirs="."
fi
echo "$layout:$entry:$dirs"
#!/usr/bin/env bash
layout="project"
if [ "$layout" = "project" ]; then
entry="bin/deploy"
dirs="bin lib test"
else
entry="./deploy.sh"
dirs="."
fi
echo "$layout:$entry:$dirs"
layout ← small
3layout="small"4if [ "$layout" = "project" ]; thenvalues this stepsmalllayoutif [ "$layout" = "project" ]; then
3layout="small"4if [ "$layout" = "project" ]; then5 entry="bin/deploy"values this stepsmalllayoutentry ← ./deploy.sh
7else8 entry="./deploy.sh"9 dirs="."values this step./deploy.shentrydirs ← .
8 entry="./deploy.sh"9 dirs="."10fivalues this step.dirsecho "$layout:$entry:$dirs"
10fi11echo "$layout:$entry:$dirs"outputsmall:./deploy.sh:.values this stepsmalllayout./deploy.shentry.dirs
layout ← project
3layout="project"4if [ "$layout" = "project" ]; thenvalues this stepprojectlayoutif [ "$layout" = "project" ]; then
3layout="project"4if [ "$layout" = "project" ]; then5 entry="bin/deploy"values this stepprojectlayoutentry ← bin/deploy
4if [ "$layout" = "project" ]; then5 entry="bin/deploy"6 dirs="bin lib test"values this stepbin/deployentrydirs ← bin lib test
5 entry="bin/deploy"6 dirs="bin lib test"7elsevalues this stepbin lib testdirsecho "$layout:$entry:$dirs"
10fi11echo "$layout:$entry:$dirs"outputproject:bin/deploy:bin lib testvalues this stepprojectlayoutbin/deployentrybin lib testdirs
layout
Layout is the file and directory shape of the script project.
entry point
The entry point is the executable script users run.
test directory
A larger layout makes room for tests beside helpers and entry points.