Shell script with string beginning with "-e"

echo, sh, shell, unix

Solution

`echo` is not a very good UNIX citizen. If it were well-behaved you'd be able to write `echo -- "$STR"`, with `--` indicating the end of the options list. But it's not, so you can't.

Your best bet is to use `printf` instead.

printf '%s\n' "$STR"

Problem

``` #!/bin/sh STR="-e" echo ${STR} STR="${STR} HI" echo ${STR} ``` The above script prints out: ``` HI ``` after a blank line. Why is this, and how do I make a string beginning with "-e"?

Original source