Gring
Gring

Reputation: 318

Escape the value of a variable in a shell script

how can I make the following work?:

var="-e"  #is entered by a user
echo $var  #should produce "-e" but does not, as the string is not escaped

The "-e" could for example be passed as input argument $1.

Thanks already :)

Upvotes: 0

Views: 1863

Answers (2)

t1m
t1m

Reputation: 43

You could try printf. For example:

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

should print out -e.

Upvotes: 1

fsw
fsw

Reputation: 3695

you probably want:

echo "${var}"

http://kvz.io/blog/2013/11/21/bash-best-practices/

Upvotes: 0

Related Questions