Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolate perl variable in shell command

Tags:

perl

I want to take date as input from User & pass that input to shell command below.

for e.g.

$date = ARGV[0];
`cd xyz $date`

will this variable be interpolated in perl?

like image 582
Rock Avatar asked May 23 '13 13:05

Rock


1 Answers

You have a couple of problems; first of all, cd only takes one parameter. Perhaps you meant something like cd xyz$date? Second, backticks start a shell that executes the command you give, which will do the change directory command and then immediately exit, having no effect. (The parent perl process's current directory is left unchanged.) You might be looking for chdir.

But yes, the interpolation will work; to disable interpolation in backticks, you either escape special characters (echo xyz \$date) or use qx with single quote delimiters (qx'echo xyz $date').

like image 136
ysth Avatar answered Sep 19 '22 18:09

ysth