Shell script with a line starting with "-e"

#!/bin/sh
STR="-e"
echo ${STR}
STR="${STR} HI"
echo ${STR}

The above script prints:

 HI

after an empty line. Why is this and how to create a line starting with "-e"?

+3
source share
1 answer

echonot a very good UNIX citizen. If that were good, you could write echo -- "$STR", with --, indicating the end of the list of options. But this is not so, therefore you cannot.

Best used printf.

printf '%s\n' "$STR"
+5
source

All Articles