Read command line parameters with Perl and Bash

By | August 8, 2009

Today I was try to pass some paramters to my CGI script directly from command line. I have a bash file which execute some perl commands and I need it to be configurable.

Bellow are two examples of how to read command line parameters, first is with Bash and second one is with Perl:

1. Read command line parameters with Bash

#!/bin/bash
echo “$# parameters”
echo “$@”;

2. Read command line parameters with Perl

#!/usr/bin/perl
foreach $argnum (0 .. $#ARGV) {
print “$ARGV[$argnum]n”;
}
That's it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.