Shell Command Chaining

lesson tools active tools/shell-command-chaining.md View on GitHub

Shell Command Chaining

Rule

Chain related shell commands in a single block instead of multiple separate executions.

Context

When executing multiple related shell commands where output feeds into the next, or when setting up and verifying a state.

Detection

Observable signals indicating need for command chaining:

Pattern

Chain related commands with appropriate operators:

# Anti-pattern: Split blocks lose context
export PROJECT_DIR=/path/to/project
# (separate block)
cd $PROJECT_DIR
# (separate block)
npm install

# Correct: Chain with && operator
export PROJECT_DIR=/path/to/project
cd $PROJECT_DIR && npm install

# OR: Single command sequence
cd /path/to/project && npm install && npm test

Operator choices:

Outcome

Following this pattern results in:

Benefits:

Related

Match Keywords

environment variable lost between blocks shell blocks lose context chain shell commands command chaining variable not found in second block shell command fails silently combine multiple commands