Developer Community

Code. Debug. Build. Share.

Ask programming questions, share code, review projects, publish tutorials, and help other developers solve real problems.

// ProfoundSyntax
function community() {
  return [
    'ask',
    'learn',
    'build',
    'share'
  ];
}
Community Feed

Unanswered Questions

0

Bash set -euo pipefail: why does my deploy script ignore some failures and exit on others?

I'm hardening a small deploy script for a Linux VPS and I'm running into the classic "set -euo pipefail" surprises. The script pulls a release, runs a build, and restarts a service. I want it to fail fast, but a few things behave differently than I expect. Here's a trimmed version:

bash
#!/usr/bin/env bash
set -euo pipefail

RELEASE_DIR="/srv/app/releases/$(date +%Y%m%d%H%M%S)"
mkdir -p "$RELEASE_DIR"

# 1) grep returning 1 (no match) kills the script here
COUNT=$(grep -c "ERROR" /var/log/app/build.log | head -n 1)

# 2) this function fails inside an if, but the script keeps going
deploy_step() {
  cp -r ./build/. "$RELEASE_DIR"
  false   # simulated failure
  echo "should not print"
}

if deploy_step; then
  echo "deploy ok"
fi

systemctl restart app.service

What I'm trying to…

Join Discussion Unanswered