3 ms·
"Like a POSIX shell" includes expanding command substitution. wordexp("`echo hi`") should return {"hi", NULL}. So it isn't totally ridiculous to reach for a she
by geofft 12y ago
"Like a POSIX shell" includes expanding command substitution. wordexp("`echo hi`") should return {"hi", NULL}. So it isn't totally ridiculous to reach for a shell; tracking multiple subprocesses, and nested command substitution (like "$(echo $(echo $(echo foo) $(echo bar)))") is a pain to reimplement correctly.
In an ideal world, we'd have a libsh that exposed all of the steps of what /bin/sh does in a nice fashion, this function would call one of the libsh functions, and /bin/sh would be a 10-line while (true) { libsh_this(); libsh_that(); }.
In a slightly less ideal world, the shell would have a way to separate things with null characters, without bothering Perl.
We really don't live in an ideal world.
- cnvogel 12y agoI understand that spawning a shell to do the expansion work probably is a good idea when your goal is to "expand a string like the shell". But my guess is that most users will call wordexp() just to expand a few variables or tilde-homedirs.
- SrslyJosh 12y ago> In an ideal world, we'd have a libsh that exposed all of the steps of what /bin/sh does in a nice fashion, this function would call one of the libsh functions, and /bin/sh would be a 10-line while (true) { libsh_this(); libsh_that(); }. THIS, GODDAMNIT, THIS.