Ashwin Singh
Ashwin Singh

Reputation: 67

A shell script for passing argument to a perl script

I am completely new to shell scripting and would really appreciate some help. Basically I want to pass a log path as argument in a shell script. Can anybody please explain to me how to do this?. A sample code would be appreciated.

Edit - I need an sh code that would pass an argument to the perl code .

Upvotes: 1

Views: 6802

Answers (1)

larsks
larsks

Reputation: 311606

If you have a perl script named, e.g., script.pl, you would pass it an argument like this:

$ perl script.pl arg1

Or, if script.pl is executable and in your $PATH, then simply:

$ script.pl arg1

Inside your perl script, you can access the command line arguments as indexes of the global @ARGV array. So to print out the first argument to your script, the code would look something like:

#!/usr/bin/perl

print "First argument: ", $ARGV[0], "\n";

Upvotes: 2

Related Questions