0

I am trying to understand what the second echo statement does exactly (it's an existing script)..

echo "Triggering report.. "
curl -s -X POST "http://aaa.bbb"
echo -e \ '\
'

I read that -e enables backslash escaping. However, not sure why there is one backslash outside, and also why there is a backslash alone inside the quote instead of \n

muru
  • 72,889
Teddy
  • 103
  • 1
    Between the quotes is a backslash that escapes the embedded newline. od shows this emits 4 bytes: space backslash-newline newline. There are better ways (like printf). – Paul_Pedant Aug 11 '22 at 07:38

1 Answers1

4

That second echo is equivalent to the following more portable command:

printf ' \\\n\n'

This outputs a space, a backslash, and two literal newline characters.

As a comparison, the echo command outputs these characters by outputting an escaped space together with a literal backslash and a literal newline character. The second newline character is added to the output by default by echo. The initial space needs to be escaped as it's not part of any quoted string (it would be removed by the shell splitting the command into words otherwise), and the backslash needs to be in a single quoted string since it otherwise would escape the next character.

The -e option used in the command does nothing here and could be dropped.

Equivalent formulations for echo (in bash):

echo -e ' \\\n'
echo ' \
'
echo -n -e ' \\\n\n'
echo -n ' \

'

See also:

Kusalananda
  • 333,661