Calling perl script in shell program

How to call a perl script in shell program / shell scripting.

PLS HELP ME

Any (well written) Perl program should probably have a shebang ( #!/usr/bin/perl .... ) in it.

In that case, call it as you would call anything else.

Same as any executable, see "man 2 exec":

1) Naming: does not matter, but popular choices are:

  • no extension (can rewrite later in any tool, like C or java)
  • .pl or .perl (tells people what it needs and that it is text)

2) Finding:

  • To use just entry name (my_perl_cmd), must be in $PATH (PATH=$PATH:/my_additional_bin_dir_path -- relative paths not recommended )
  • Else (declasse even when developing), must give a good, explicit relative or absolute path ( /my_additional_bin_dir_path/my_perl_cmd ).

3) Calling:

  • To be called without mentioning PERL, must be executable to you in file mode, and have the interpreter full path (/usr/bin/perl or whatever) and optionally one argument after #! on the first line.
  • Else (declasse even when developing), you can call perl directly and pass the script as a command line argument [ programfile ], which requires it has any necessary path and probably only be file mode readable to you. If perl is not in your PATH, it needs a relative or absolute path.
$ man perl
Reformatting entry.  Wait...


 PERL(1)                         2001-12-07                          PERL(1)
 Perl Programmers Reference Guide           Perl Programmers Reference Guide

                                 perl v5.6.1



 NAME
      perl - Practical Extraction and Report Language

 SYNOPSIS
      perl [ -sTuU ] [ -hv ] [ -V[:configvar] ]
          [ -cw ] [ -d[:debugger] ] [ -D[number/list] ]
          [ -pna ] [ -Fpattern ] [ -l[octal] ] [ -0[octal] ]
          [ -Idir ] [ -m[-]module ] [ -M[-]'module...' ]
          [ -P ] [ -S ] [ -x[dir] ]
          [ -i[extension] ] [ -e 'command' ] [ --
       ] [ programfile ] [ argument ]...