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:
#!/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.serviceWhat I'm trying to…

