Package: base-files Version: 11.1 Severity: normal
Hi. (CCing Georgios M. Zarkadas from #632887 for his comments on (3) below, if any.) Currently /usr/share/base-files/profile has: if [ "${PS1-}" ]; then if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then and /usr/share/base-files/dot.profile has: if [ "$BASH" ]; then I think there are several issues with that, respectively possible improvements: 1) I'd say, both should do the same (i.e. /etc/profile and ~/.profile), so that should be aligned. 2) /etc/bash.bashrc already checks whether run interactively, so if it's just for whether /etc/bash.bashrc shall be sourced or not, the `if [ "${PS1-}" ]; then` is not really needed (other than avoiding the sourcing). But even then, using PS1 is IMO not optimal. The variable may exist in a non-interactive shell (e.g. when exported in a calling parent shell). The following: if [ -n "${-##*i*}" ] || [ -z "${-}" ]; then return fi uses the shell options which, I guess, one can assume are always right. The above code should be POSIXly correct and unlike some constructs with `case` avoid the hypothetical issue of a future option "I" being mistaken for "i", when bash's nocasematch option would be on. 3) The check for /bin/sh: - Shouldn't that also be in .profile? - Shouddn't it also cover the sourcing of /etc/profile.d/*.sh (for the same reasons)? - The check itself is IMO problematic: bash's manual talks about the "sh-like-behaviour" when invoked as `sh`, not necessarily as `/bin/sh`. Also this would break, should sh ever go to /usr/bin/sh as part of the usr-merge. So, wouldn't it be better to check e.g.: if [ -z "${0##*/sh}" ] || [ "$0" = sh ] ; then #it's run as sh ? I think $0 can never be empty, so there's no need to check that it's actually set to something. 4) $BASH might be bogus. Just export BASH, and then run dash... Well, it's no our business to prevent users from shooting themselves, at least not to every extent. But one could do: if [ -n "${BASH-}" ] && { [ "$(ps -p $$ -o exe=)" = /usr/bin/bash ] || [ "$(ps -p $$ -o exe=)" = /bin/bash ]; }; then That has the short-circuit that if BASH is not there, don't source bashrc. So there should be nearly no speed impact for shell scripts. But if it's there, the above would also check whether the executable is actually /usr/bin/bash or /bin/bash. The above is not fully POSIX-compatible (POSIX ps has no "exe"). Calling ps twice is a bit ugly... but I see no other way than using a helper variable. Maybe the `i` can be used, which is already used below when sourcing /etc/profile.d/*.sh . Also, ps isn't guaranteed to be there (procps isn't essential). So either one would need to check for that... or e.g. use /proc/$$/exe Cheers, Chris.