phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

Escape sequences in command parameters are incorrectly consumed by the shell

Open AtkinsSJ opened this issue 1 year ago • 1 comments

For example, echo "\n\n\n\n\n" emits only a single newline, because echo always emits a newline after its output. When that string reaches echo as a positional argument, the newline escapes are gone.

As another example, echo "hello\nfriends\n" currently outputs this from a console.log() call:

{
  allowPositionals: true,
  options: {
    'no-newline': {
      description: 'Do not print a trailing newline',
      type: 'boolean',
      short: 'n'
    },
    'enable-escapes': {
      description: 'Interpret backslash escape sequences',
      type: 'boolean',
      short: 'e'
    },
    'disable-escapes': {
      description: 'Disable interpreting backslash escape sequences',
      type: 'boolean',
      short: 'E'
    }
  },
  args: [ 'hellofriends' ]
}

As you can see, args is 'hellofriends' without the escapes.

AtkinsSJ avatar Mar 06 '24 13:03 AtkinsSJ

Just to avoid confusion since the correct output wasn't mentioned, echo "\n" should output the string "\n" literally (i.e. "\n" as a json string) unless the -e flag is specified, in which case it does output a line feed.

KernelDeimos avatar Mar 08 '24 14:03 KernelDeimos