/bin/bash: line 33: warning: here-document at line 5 delimited by end-of-file (wanted `CURSOR_SNAP_EOF_%sn \"$var_name\" \"$var_name\"
base64 -w 0 <<<\"$content\"
printf nCURSOR_SNAP_EOF_%sn \"$var_name\"
printf ')
/bin/bash: -c: line 1: unexpected EOF while looking for matching `)'
I used promon to check the processes when cursor starts. Here is the problematic command. I saved it directly as a .sh file and ran it with bash, and encountered the same issue.
bash -lc "#!/usr/bin/env bash
# Usage:
# source dump_bash_state.bash
# dump_bash_state OUTPUT_FILE
# Or execute directly (captures a subshell's state):
# ./dump_bash_state.bash OUTPUT_FILE
dump_bash_state() {
set -euo pipefail
# Require base64 for safe encoding of emitted sections
if ! command -v base64 >/dev/null 2>&1; then
echo \"Error: base64 command is required\" >&2
return 1
fi
# Helper to log timing, only if DUMP_BASH_STATE_TIMING is set
if [[ -n \"${DUMP_BASH_STATE_TIMING:-}\" ]]; then
# Timing setup
if [[ \"${BASH_VERSION%%.*}\" -ge 5 ]]; then
# Use EPOCHREALTIME if available (bash 5+)
local start_time=${EPOCHREALTIME}
local step_start=${EPOCHREALTIME}
_log_timing() {
local step_name=\"$1\"
local now=${EPOCHREALTIME}
local step_duration=$(awk \"BEGIN {printf \"%.3f\", $now - $step_start}\")
local total_duration=$(awk \"BEGIN {printf \"%.3f\", $now - $start_time}\")
printf \"[TIMING] %-20s: %6.3fs (total: %6.3fs)
\" \"$step_name\" \"$step_duration\" \"$total_duration\" >&2
step_start=$now
}
else
# Fallback for older bash versions
local start_time=$(date +%s.%N)
local step_start=$(date +%s.%N)
_log_timing() {
local step_name=\"$1\"
local now=$(date +%s.%N)
local step_duration=$(awk \"BEGIN {printf \"%.3f\", $now - $step_start}\")
local total_duration=$(awk \"BEGIN {printf \"%.3f\", $now - $start_time}\")
printf \"[TIMING] %-20s: %6.3fs (total: %6.3fs)
\" \"$step_name\" \"$step_duration\" \"$total_duration\" >&2
step_start=$now
}
fi
else
_log_timing() { :; }
fi
# Helper to append a line to output file
_emit() {
printf '%s\n' \"$1\"
}
# Helper to safely encode and emit unsafe values
_emit_encoded() {
local content=\"$1\"
local var_name=\"$2\"
if [[ -n \"$content\" ]]; then
# Use here-document to avoid argument list length limits entirely
printf 'cursor_snap_%s=$(base64 -d <<'''CURSOR_SNAP_EOF_%s'''\n' \"$var_name\" \"$var_name\"
base64 -w 0 <<<\"$content\"
printf '\nCURSOR_SNAP_EOF_%s\n' \"$var_name\"
printf ')\n'
printf 'eval \"$cursor_snap_%s\"\n' \"$var_name\"
fi
}
# Start fresh
_log_timing \"file_init\"
# Working directory
_emit \"$PWD\"
_log_timing \"working_dir\"
# Environment variables (export statements)
local env_vars
env_vars=$(export -p 2>/dev/null || true)
_emit_encoded \"$env_vars\" \"ENV_VARS_B64\"
_log_timing \"environment\"
# Functions: capture all functions
local all_functions
all_functions=$(declare -f 2>/dev/null || true)
_emit_encoded \"$all_functions\" \"FUNCTIONS_B64\"
_log_timing \"functions\"
# Done
_log_timing \"finalize\"
}
dump_bash_state >&4"