On Sep 10, 2014, at 4:58 AM, Vincent Lefevre <vinc...@vinc17.net> wrote:
> In error messages, raw non-printable characters from arguments should > not be output without transformation, at least if this is on a terminal. > If stderr has been redirected, this is more a matter of choice. > > An example: type "cd /^M" where ^M is a CR character (e.g. obtained by > typing ^V ^M). One gets on the terminal: > > : No such file or directory > > which is not very informative... One of many arguments why command error errors should be handled, and why interpreted data in messages should be surrounded by quotes (not quoted, but surrounded by quotes). As an example, this is much more effective for ugly values of $LOG like control-M or " dir name": # Empty the log directory if ! cd "$LOG" ; then echo "Directory '$LOG' doesn't exist or not accessible, halting." exit 1 fi # take actions here... rm * is a helluva lot more sensible than cd $LOG # take actions here... rm * > IMHO, in this case, bash should do like zsh, which replaces the CR > character by the character sequence "^M". This doesn't seem like a good idea. At our site it leads our zsh users to send us complaints that they don't have a file with the two-character name ^M. Beyond there, there are several drawbacks. I'd hate to see the built-in echo diverge from system /bin/echo (or diverge further, as the case may be). It would also break this current behavior: CLEAR_SCREEN=$(tput clear) echo $CLEAR_SCREEN By comparison, checking returns from commands like cd and surrounding echoed/printed parameters by quotes will work for pretty much all legacy bash/ksh/sh shells, maybe zsh as well. I believe that perl has some sort of quote function that takes a string with non-printable chars and converts them to ^M, \033, etc. That, used judiciously, strikes me as more sensible. Of course, you'd still have to use and quote it properly. For $LOG values like ' dir name' or control-M or not defined, consider the ways this can go wrong: if ! cd $LOG ; then echo Directory $(quoteme $LOG) does not exist or not accessible. exit 1 fi rm * vs this: if ! cd "$LOG" ; then print "Directory '%s' does not exist.\n" "$(quoteme "$LOG")" exit 1 fi rm * Steve