I am trying to store the string "-e test" in a bash variable. For some reason, it removes the "-e " part from the string. I cannot figure out how to escape this.
Test script:
var="-e test"
echo $var
Expected output:
-e test
Actual output:
test
The problem is that your variable is expanded such that:
echo $var
becomes:
echo -e test
Where -e is a valid argument to echo. The variable is being stored correctly, but you're using it in a way that doesn't print it out correctly.
To ensure that there aren't unintended consequences like this, simply put quotes around the variable when using it:
echo "$var"
Which would be expanded by the shell to:
echo "-e test"
