In the Bash Pitfalls on "Greg's Wiki" I found the following quote:
In fact, the echo
echocommand cannot be used with absolute safety here. If the variable contains -n-nfor example, echoechowill consider that an option, rather than data to be printed. The only absolutely sure way to print the value of a variable is using print:printf "%s\n" "$foo"source:printf "%s\n" "$foo"
WhenBut when I type:
var="-n Hello" echo "$var" var="-n Hello" echo "$var" It works properly and doesn't interpret -n-n as an option, so I don't understand why the source I quoted says that we need to use printfprintf to be absolutely safe?