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.

layout
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"
  1. layout ← small

    3layout="small"4if [ "$layout" = "project" ]; then
    values this stepsmalllayout
  2. if [ "$layout" = "project" ]; then

    3layout="small"4if [ "$layout" = "project" ]; then5    entry="bin/deploy"
    values this stepsmalllayout
  3. entry ← ./deploy.sh

    7else8    entry="./deploy.sh"9    dirs="."
    values this step./deploy.shentry
  4. dirs ← .

    8    entry="./deploy.sh"9    dirs="."10fi
    values this step.dirs
  5. echo "$layout:$entry:$dirs"

    10fi11echo "$layout:$entry:$dirs"
    outputsmall:./deploy.sh:.
    values this stepsmalllayout./deploy.shentry.dirs
  1. layout ← project

    3layout="project"4if [ "$layout" = "project" ]; then
    values this stepprojectlayout
  2. if [ "$layout" = "project" ]; then

    3layout="project"4if [ "$layout" = "project" ]; then5    entry="bin/deploy"
    values this stepprojectlayout
  3. entry ← bin/deploy

    4if [ "$layout" = "project" ]; then5    entry="bin/deploy"6    dirs="bin lib test"
    values this stepbin/deployentry
  4. dirs ← bin lib test

    5    entry="bin/deploy"6    dirs="bin lib test"7else
    values this stepbin lib testdirs
  5. echo "$layout:$entry:$dirs"

    10fi11echo "$layout:$entry:$dirs"
    outputproject:bin/deploy:bin lib test
    values 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.