Thorsten Glaser schreef op 30-06-15 om 16:55: > Hrm, why do people use these things so much which I never use in > any scripts at all? This, and 'type'b &
Well, since you asked, I'll explain my use case. I'm implementing feature testing in a cross-platform POSIX shell library (inspired by modernizr and jQuery for JavaScript) that extends the POSIX shell language with new functionality. One aspect of feature testing is determining if some word is a reserved word or shell built-in in the current shell. I need to do it in a cross-platform way as much as possible. My general strategy for determining whether "$1" is a shell keyword or builtin function is to test the exit status of the following subshell block: ( unalias "$1" unset -f "$1" PATH=/dev/null command -v "$1" ) >/dev/null I found that shell keywords such as 'select' are not found like this on mksh, though they are found on ksh93, bash and zsh. Currently, mksh needs its own version of the above code, where 'whence' is used in place of 'command -v'. By the way, writing such a cross-platform library is a great way to find all kinds of obscure shell bugs in various shells. And I have to say that I found virtually none of them in mksh; this here is the first, and it's pretty minor. The improvement over pdksh is radical (I gave up on supporting pdksh when I found that "$@" does not work correctly if IFS is empty). mksh is one solid shell; hat off! > Can you enumerate the b shell reserved wordsb , so I have an idea what > to include? (Thinking of && and > and so onb &) This is pure bloat, as > it will have to be included in another tableb & && and > are shell grammar operators, not reserved words, and 'command' is not supposed to find them. 'command -V' (with capital V) is already capable of identifying reserved words correctly, so (from where I sit) it seems like the table you want should already exist, and it shouldn't take more than make the '-v' option query it in the same way that '-V' does. I know nothing about the mksh code though, so I could be wrong. If you want, I can investigate and take a stab at creating a patch. Also, the 'whence' command (without any option) already acts like 'command -v' should, except for aliases where the output format doesn't include the alias command. Here is the POSIX reference on reserved words, but (m)ksh, zsh and bash have additional reserved words, such as 'select'. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_04 Hope this helps, - M.
