Shell scripting notes

From raju

Call perl script from shell

Create the shell script as follows. It is basically a pass through for the perl function.

=> cat hello
#! /bin/tcsh -f

~/work/perl/from_shell_script/hello.pl $*

Now create a simple perl script that dumps its arguments.

=> cat hello.pl
#! /usr/bin/perl -w

use strict;
use warnings;
use Data::Dumper qw(Dumper);

print Dumper \@ARGV;

Run the perl program

=> ./hello.pl -a -b raju
$VAR1 = [
          '-a',
          '-b',
          'raju'
        ];

Same as above except that we use the shell wrapper.

=> ./hello -a -b raju
$VAR1 = [
          '-a',
          '-b',
          'raju'
        ];

Shell expands the arguments before passing it to the calling scripts.

=> ls
hello*  hello.pl*

=> ./hello hello*
$VAR1 = [
          'hello',
          'hello.pl'
        ];

=> ./hello "hello*"
$VAR1 = [
          'hello',
          'hello.pl'
        ];

=> ./hello 'hello*'
$VAR1 = [
          'hello',
          'hello.pl'
        ];