在shell脚本中转义变量的值

在shell脚本中转义变量的值,shell,escaping,Shell,Escaping,我如何做以下工作 var="-e" #is entered by a user echo $var #should produce "-e" but does not, as the string is not escaped 例如,-e可以作为输入参数$1传递 已经谢谢了:您可能想要: echo "${var}" 你可以试试printf。 例如: var="-e" printf %s "$var" 应该打印出-e。这并没有给我带来什么区别:/它仍然不会显示-e

我如何做以下工作

var="-e"  #is entered by a user
echo $var  #should produce "-e" but does not, as the string is not escaped
例如,-e可以作为输入参数$1传递

已经谢谢了:

您可能想要:

echo "${var}"
你可以试试printf。 例如:

var="-e"
printf %s "$var"

应该打印出-e。

这并没有给我带来什么区别:/它仍然不会显示-e