AnnaSchumann AnnaSchumann - 1 year ago 50
Perl Question

Passing arguments to perl using bash variables

Ordinarily I would invoke Perl and supply required arguments from within a bash script simply using:

perl arg1

However there are cases when I want to store both the perl script directory and the arguments in bash variables:

PERLDIR = "/example/directory/"
ARG1 = "40"

When trying to call the perl script using:

perl "$PERLDIR"

It works, however when trying to provide the argument i'm not sure of the syntax to utilise. If I use:

perl "$PERLDIR $ARG1"
it'll attempt to open the directory:

/example/directory/ 40

And throw an error.

Is there a way to do this and if so, how?


You should use:

 perl "$PERLDIR" "$ARG1"

When you use many variables in one string enclosed with " it becomes one argument.