Ticket #399 (closed crash: fixed)
bashisms in startx with __APPLE__
| Reported by: | dos@… | Owned by: | jeremyhu@… |
|---|---|---|---|
| Priority: | Nice to Have | Milestone: | 2.5.1 |
| Component: | x11-apps | Version: | 2.5.0 (xserver-1.7.6) |
| Keywords: | xinit startx | Cc: |
Description
Several shell constructs used in startx when the __APPLE__ preprocessor symbol is defined aren't generally compatible with POSIX shells. The shebang line of startx is /bin/sh.
>& /dev/null
In POSIX sh, >&word is only used for duplicating one fd to another. Redirecting to a file doesn't make sense (according to the standard, "if the digits in word do not represent a file descriptor already open for output, a redirection error shall result"). However, bash treats that syntax as redirecting both standard output and standard error to a file. We can just be less lazy and use > /dev/null 2> /dev/null instead.
for ((d=0; ; d++)) ; do
POSIX sh doesn't support this C-like for-loop. We can just expand it into a while loop. I've used $(($d + 1)) to do the increment, which is guaranteed by POSIX, but if you wanted to be even more portable you could do $(expr $d + 1).
${serverargs}" -auth '"${xserverauthfile//\'/\'\\\'\'}"'"
The ${parameter/pattern/string} is a bash construct, nothing close exists in the POSIX shell. We can however use sed to do exactly the same thing, given that the startx script already uses sed 10 lines down anyway.
With all this said, bash is usually the default /bin/sh on OS X. However, it doesn't cost much to be a bit more portable. Patch attached.

