Alex F
Alex F

Reputation: 43331

Using bash variable in perl parameter

Ubuntu, terminal window, bash shell:

alex@d120432:~$ echo $0
bash
alex@d120432:~$ echo $(perl -e 'print "a"x2')
aa
alex@d120432:~$ i=2
echo $i
2
alex@d120432:~$ echo $(perl -e 'print "a"x$i')

alex@d120432:~$

Is there syntax which allows to substitute $i with 2, so that the second echo command prints xx like the first one?

Upvotes: 1

Views: 29

Answers (1)

anubhava
anubhava

Reputation: 786349

You need to get quoting right:

i=2
perl -le "print 'a' x $i"

aa

Upvotes: 1

Related Questions