Calling perl script in shell program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling perl script in shell program
# 1  
Old 10-20-2010
Calling perl script in shell program

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

PLS HELP ME
# 2  
Old 10-20-2010
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.
# 3  
Old 10-20-2010
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.

Code:
$ 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 ]...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling perl from shell script

I am calling a perl script from shell script. $ cat mah_appln_bkp_oln.ksh #!/bin/ksh . /udb/home/udbappln/.profile . /udb/home/udbappln/sqllib/db2profile Com=/udb/udbappln/utility/systemscripts/currentUMR perl $Com/backup.pl -d dbname --tsm --purgetsmcopies 21 --purgetsmlogs exit 0 ... (1 Reply)
Discussion started by: ilugopal
1 Replies

2. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

3. Shell Programming and Scripting

Calling perl subroutine from shell script (sh)

Hi, ive a perl script, where it has a subroutine clear() in it, and i've one shell script which runs in background, from that shell script i wanted to call subroutine which is in perl script, that's perl script is not module, just simple script. Eg: perl script <test> #!... (4 Replies)
Discussion started by: asarunkumar
4 Replies

4. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

5. Programming

Calling a shell script from a C program

Hi, I have a shell script which connects to a database and fetches the count of the records from a table. I want to embed this whole script in a C program. Also the count fetched should be available in the C program for further usage. Please let me know how this can be done. Thanks (9 Replies)
Discussion started by: swasid
9 Replies

6. Shell Programming and Scripting

Calling a shell script from a C program

Hi, I have a shell script which connects to a database and fetches the count of the records from a table. I want to embed this whole script in a C program. Also the count fetched should be available in the C program for further usage. Please let me know how this can be done. Thanks ... (0 Replies)
Discussion started by: swasid
0 Replies

7. UNIX for Dummies Questions & Answers

Calling a c program using perl script

On bash I run precompiled c Program as follows: ./create_cust 1 10000 US S > us_cust.csv create_cust is a c program and requires 4 parameters. I am redirecting the output of this program to csv file I need to run this same program in perl I am aware of exec command though not... (7 Replies)
Discussion started by: gkbond
7 Replies

8. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l) here's the mode script: #!/bin/sh octal="$1" shift find . -maxdepth 1 -perm $octal -exec $@ {} \; ... (3 Replies)
Discussion started by: computethis
3 Replies

9. Shell Programming and Scripting

Calling SHELL script from C program

Hi, I just tried to call a simple script from a pretty simple C program. I could not succeed :-( a message was thrown saying "sh: line 1: "Script name with path": Permission denied" The C program and shell script are below, both are in the same directory and shell script is given... (7 Replies)
Discussion started by: Chanakya.m
7 Replies

10. Shell Programming and Scripting

calling a shell script from perl

Hi all, Not sure if this is the right forum to post query regarding perl script. I have a perl script which internally calls a shell script. My problem is that the shell script should be passed command line arguments. I call a shell script from perl using: system("sript.sh"); How do... (3 Replies)
Discussion started by: gurukottur
3 Replies
Login or Register to Ask a Question