cjm2671
cjm2671

Reputation: 19456

Escaping in a sh script?

I've got the following line in my script:

xrandr --newmode "$xx$y" $m

where $x and $y are integers, to produce an output like 1024x768.

Unfortunately my script is interpreting the $x as $xx - how can I stop this & get the desired behavior?

Upvotes: 1

Views: 53

Answers (2)

Jahid
Jahid

Reputation: 22428

The general logic is to isolate the variable so that it doesn't take xx as the variable name. There are several ways to do that:

Using quotes:

x="xvar";y="yvar"
echo ""$x"x$y"
echo ""$x"x"$y""
echo "$x""x""$y"
echo "$x"x"$y"

Using brace (mentioned by Alberto Zaccagni):

echo "${x}x$y"

Upvotes: 1

Alberto Zaccagni
Alberto Zaccagni

Reputation: 31560

You could try to do it this way

"${x}x$y"

Have a look at the docs for more info.

Upvotes: 5

Related Questions