Affected versions: FreeBSD 12

πŸ“– ~1 min read

Table of contents
  1. Symptom & Impact
  2. Environment & Reproduction
  3. Root Cause Analysis
  4. Quick Triage
  5. Step-by-Step Diagnosis
  6. Solution – Primary Fix
  7. Solution – Alternative Approaches
  8. Verification & Acceptance Criteria
  9. Rollback Plan
  10. Prevention & Hardening
  11. Related Errors & Cross-Refs
  12. References & Further Reading

Symptom & Impact

Custom service script fails at startup with bad substitution, preventing daemon launch after system boot.

Environment & Reproduction

service start immediately exits when script contains Bash-only parameter expansion under /bin/sh.

Root Cause Analysis

Scripts written for Bash are executed by default FreeBSD /bin/sh in rc.d, causing syntax incompatibility.

Quick Triage

Run sh -n script, enable set -x, and inspect shebang plus substitution expressions unsupported by POSIX sh.

Step-by-Step Diagnosis

Identify non-portable constructs and compare script behavior under sh and bash shells explicitly. image_ref=0

Illustrative mockup for freebsd-12 β€” terminal_or_shell
Running service scripts with tracing enabled β€” Illustrative mockup β€” Progressive Robot

Solution – Primary Fix

Rewrite script to POSIX-compliant syntax or set an explicit bash shebang with dependency availability checks. image_ref=1

Still having issues? Our IT Solutions & Services team can diagnose and resolve this for you. Get in touch for a free consultation.

Illustrative mockup for freebsd-12 β€” log_or_config
Reviewing rc.d script shebang and parameter expansion β€” Illustrative mockup β€” Progressive Robot

Solution – Alternative Approaches

Wrap complex startup logic in tested helper binaries and keep rc.d scripts minimal and portable.

Verification & Acceptance Criteria

Script passes sh -n validation and service starts cleanly via rc.d during reboot testing.

Rollback Plan

Reinstate previous working rc.d script version and defer advanced logic until portability fixes are complete.

Prevention & Hardening

Enforce shellcheck in CI and require POSIX compatibility reviews for all rc.d managed scripts.

Related errors include not found function syntax, arithmetic expansion failures, and unset variable exits.

Related tutorial: View the step-by-step tutorial for freebsd-12.

View all freebsd-12 tutorials on the Tutorials Hub β†’

Browse all common problems & solutions on the Tutorials Hub.

References & Further Reading

Consult man sh, man rc.subr, and FreeBSD rc.d scripting conventions.

Need Expert Help?

If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today β€” we respond within one business day.