4 ms·
That means that you have to write everything to temporary files first. If you want to do that then maybe Python is already more convenient.
by jstimpfle 10y ago
That means that you have to write everything to temporary files first. If you want to do that then maybe Python is already more convenient.
- marcosdumay 10y agoIf you are doing anything with complex behavior that requires error checking, interpolating strings with possibly invalid values, or just writing a lot of code, then Python is already more convenient and if you didn't notice it is because you are hiding a lot of Bash problems under a carpet.
- jstimpfle 10y agoThat's my point. It's not easy and often impossible to write robust shell scripts. Part of it is the problem domain. Rewriting any slightly complex bash script in e.g. Python with robust error handling can be quite challenging. You have to make a number of very difficult decisions.
- kps 10y ago> That means that you have to write everything to temporary files first. Using the example from the post, echo "($(ldap-query-for-valid-users))" > "/tmp/all-users.sexp" you have at least a couple alternatives to an additional temporary file. if ! valid__users=$(ldap-query-for-valid-users) then ... failure case ... fi echo "($valid__users)" >/tmp/all-users.sexp or { echo -n '(' if ! ldap-query-for-valid-users then ... failure case ... fi echo ')' } >/tmp/all-users.sexp
- jstimpfle 10y agoAs an aside, command substitution can't handle binary, and it strips all trailing newlines.
- btilly 10y agoAnd when multiple bash scripts do that, it is easy to have them accidentally overwrite each other's temp files. Plus an attacker can play with temp files in a number of interesting ways to turn their use into an attack.
- kps 10y agoI was just illustrating the error checking using commands functionally equivalent to the original post. Temporary files are best avoided entirely unless some command actually requires a seekable file, in which case use mktemp(1) or equivalent (and 'trap 0' to clean up after yourself).