Automatic special character escaping in Bash scripts?
I would like to basically do the opposite of "echo -e" or "echo $'stuff'". That is, instead of interpreting the escaped special C-like sequences, such as \n, my Bash script would print the supplied string with everything special and non-printable in the backslash-escaped form.
It surprises me that this kind of functionality doesn't seem to be implemented as (or in) a normal utility like echo. Programs like ls seem to use such routines (--quoting-style argument). The task is probably easy with Perl, Python or some such language, but it seems a bit overkill and I'd like to do it in a shell script. If I were to make the function myself, I would have to be able to turn characters into octal sequences.