eselect-python generated /usr/bin/python wrapper uses shebang pointing to /bin/sh while the same script uses heavy bashisms. Thus, if user has changed /bin/sh symlink to point to any shell stricter than bash, script fails to execute python and user becomes even unable to run emerge. This script should be shebanged /bin/bash or changed to use only POSIX shell-compatible syntax.
AFAICS 'python' wrapper is very easy to unbashize (replace this pointless pattern match with '[ -z "${EPYTHON}" ] || [ "${EPYTHON}" = "python" ]') but second one uses bash in more serious way. I would like to notice that both scripts should use 'exec' at the end, to avoid polluting pidspace.
We will change this wrapper to use /bin/bash. (In reply to comment #1) > I would like to notice that both scripts should use 'exec' at the end I tested it and it breaks displaying application name in title bar of terminal.
(In reply to comment #1) > replace this pointless pattern match with > '[ -z "${EPYTHON}" ] || [ "${EPYTHON}" = "python" ]' '[[ "${EPYTHON}" =~ (/|^python$) ]]' means that we don't support including '/' character in "${EPYTHON}". '^python$' is used to avoid infinite recursion.
Fixed.
(In reply to comment #3) I do not understand which script you mean (eselect-python-20090606 generates symlinks), so I cannot check it. However, the POSIX rewrite of [[ "${EPYTHON}" =~ (/|^python$) ]] would be easy: ! case "${EPYTHON}" in */*|python) false;; esac
(In reply to comment #5) > However, the POSIX rewrite of [[ "${EPYTHON}" =~ (/|^python$) ]] > would be easy: > ! case "${EPYTHON}" in */*|python) false;; esac And the code would be more ugly...
Now I got the new portage and finally could look at the actual script. In the content of this script, there is a much simpler POSIX equivalent: Instead of [[ "\${EPYTHON}" =~ (/|^python$) ]] && EPYTHON="${target}" one could just use case "\${EPYTHON}" in */*|python) EPYTHON="${target}";; esac or, if you really think readability is an issue here: case "\${EPYTHON}" in */*|python) EPYTHON="${target}";; esac I do not want to discuss uglyness (although opinions may differ). But the main advantage of pretty much any /bin/sh over bash is that it needs less memory and less time for loading and initialization than bash: For a wrapper script of an interpreter language which is presumable called pretty often from user's scripts, time and memory usage is an important point IMHO.
@Martin Väth: Take a look at python-config, I don't think we could do this nice without calling external tools or using bashisms. (In reply to comment #2) > I tested it and it breaks displaying application name in title bar of terminal. I don't think that titlebar issue should be more important than keeping additional, useless process issue. Could you provide some example how can I trigger this issue?
(In reply to comment #7) > Take a look at python-config I do not think that it is so important to avoid bash here, since this is probably not called as frequently as python itself. Anyway, I see no problem: python_config="${EPYTHON/python/python-config-} could be rewritten in POSIX only slightly more complicated: python_config="${EPYTHON%%python*}python-config${EPYTHON#*python}"
Created attachment 199837 [details, diff] bash -> POSIX for the wrapper scripts In my previous remark, I made two small mistakes: 1. A typo: "-config" should be "-config-". 2. I forgot the trivial case when EPYTHON does not contain "python". Instead of attaching further code pieces, I attach a full patch for the eselect-python module. The patch assumes that comment #4 was already applied - it did not hit my portage tree so far, so I have to make some assumptions here...