Why does/would the following printf statement behave differently based upon ...? (GNU bash, version 4.4.18(1)-release (x86_64-pc-linux-gnu))
printf "%s : %s : %s\n" $TERM ${TERM//[^[:alnum:]]/_} ${TERM//[^[:alnum:]]/?}
When in an unprivileged user terminal session in tmux, the output is:
screen-256color : screen_256color : screen?256color
However, when in a root terminal, for the same tmux session the output is:
xterm-256color : xterm_256color :
Outside of tmux, the output is the same failure for all users:
xterm-256color : xterm_256color :
ADDITIONAL INFORMATION:
I just tried the same command line, but replacing the question mark with an asterisk, and the same failures and successes occur. Could it be an issue related somehow to globbing? The field is supposed to be treated as a string value, not a glob. Then I tried escaping the character and get the following results, for the six cases of asterisk plain, with one backslash, and with two backslashes, for xterm-256color and screen-256-color cases mentioned above:
printf "%s : %s : %s\n" $TERM ${TERM//[^[:alnum:]]/_} ${TERM//[^[:alnum:]]/*}
screen-256color : screen_256color : screen*256color
xterm-256color : xterm_256color :
printf "%s : %s : %s\n" $TERM ${TERM//[^[:alnum:]]/_} ${TERM//[^[:alnum:]]/\*}
screen-256color : screen_256color : screen*256color
xterm-256color : xterm_256color :
printf "%s : %s : %s\n" $TERM ${TERM//[^[:alnum:]]/_} ${TERM//[^[:alnum:]]/\\*}
screen-256color : screen_256color : screen\*256color
xterm-256color : xterm_256color : xterm\*256color