0

I have a bash file, that takes one argument. This is used within ConfD CLI, for a command. However, if the user uses \r metacharacter, it throws my program off.

Example (on ConfD shell):

somecommand hellooooo\rtest

On displaying $@ within my bash file:

testooooo

Any suggestions on how to tackle this? Or is there a way to disable use of metacharacter for ConfD CLI itself?

Shravan J Kumar
  • 158
  • 1
  • 1
  • 10
  • "displaying $@" how? There are lots of wrong ways to do it. (Any approach that involves `echo` is quite deeply broken; `printf ' - %q\n' "$@"` is one of the right ways). – Charles Duffy Mar 14 '18 at 22:36
  • 1
    See the RATIONALE and APPLICATION USAGE sections of http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html for some background re: how `echo` came to be broken-by-design, and why it's still around despite that. – Charles Duffy Mar 14 '18 at 22:38
  • 2
    ...anyhow, right now, you aren't showing your actual code, which makes this effectively unanswerable. – Charles Duffy Mar 14 '18 at 22:39
  • 1
    Are you talking about the user using a literal `\r` (backslash character followed by the letter "r"), or a carriage return character (ASCII code 13 aka control-M, sometimes represented as `\r` or `^M` or `` or...)? Also, how does it throw the program off; does it just display wrong, or is there more to it than that? – Gordon Davisson Mar 14 '18 at 23:01
  • The variable doesn't contain `testooooo`, that's purely a display artifact. It has the correct value, and you can treat it as such. – that other guy Mar 15 '18 at 09:22
  • Thanks for all your comments, since posting the question I have read up and realized that echo was interpreting the \r. I have used regex on $@ to handle this issue. – Shravan J Kumar Mar 16 '18 at 18:37

0 Answers0