3 ms·
That's actually one of the things that I really dislike with bash, that it doesn't read the whole script before executing it. I've been bitten by it before, whe
by unhammer 12y ago
That's actually one of the things that I really dislike with bash, that it doesn't read the whole script before executing it. I've been bitten by it before, when I write some long-running script, then e.g. write a comment at the top of it as it's running, and then when bash looks for the next command, it's shifted a bit and I get (at best) a syntax error and have to re-run :-(
- lsaferite 12y agoEwww. Thats... nasty and dangerous. Very dangerous.
- LukeShu 12y agoThere are several ways to get Bash to read the whole thing before executing. My preferred method is to write a main() function, and call main "$@" at the very end of the script. Another trick, useful for shorter scripts, is to just wrap the body of the script in {}, which causes the script to be a giant compound command that is parsed before any of it is executed; instead of a list of commands that is executed as read.
- unhammer 12y agoAh, thank you for that. I may just start using these tricks in all my scripts :-)