Wrap script in main() to prevent line-by-line execution bug

When run via `bash <(curl ...)`, bash reads the script incrementally
from a process substitution fd. If a `read < /dev/tty` call disrupts
the fd state, bash can lose its place and the remaining script lines
get fed to the interactive shell prompt as individual commands.

Wrapping everything in main() forces bash to parse the entire script
into memory before executing any of it — the standard fix for
curl-piped scripts.

Also changed README one-liner to download-then-execute pattern
(curl -o /tmp/... && bash /tmp/...) as a belt-and-suspenders approach.

https://claude.ai/code/session_01XKYC1basxdwtHy71tky7xm
This commit is contained in:
Claude
2026-03-25 13:37:29 +00:00
parent 1c7866bc0a
commit cc847cff67
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
## Quick install
```bash
bash <(curl -fsSL https://raw.githubusercontent.com/outis1one/openwhispr-easy-setup/main/setup-openwhispr.sh)
curl -fsSL https://raw.githubusercontent.com/outis1one/openwhispr-easy-setup/main/setup-openwhispr.sh -o /tmp/setup-openwhispr.sh && bash /tmp/setup-openwhispr.sh
```
Or clone and run:
+13
View File
@@ -3,6 +3,14 @@
# https://github.com/outis1one/openwhispr-easy-setup
# License: MIT
# ── Wrap everything in main() so bash reads the entire script before executing.
# This prevents the "line-by-line interpreted as commands" bug when run via:
# bash <(curl -fsSL ...) or curl ... | bash
# Without this wrapper, bash may lose track of the script source after a read
# from /dev/tty and start feeding remaining script lines to the shell prompt.
main() {
# Do NOT use set -e — we handle errors explicitly
readonly SCRIPT_VERSION="1.0.0"
@@ -653,3 +661,8 @@ cat <<EOF
EOF
divider
printf "\n"
} # end main()
# Call main — this ensures the entire script is parsed before execution
main "$@"