Copyright © tutorialspoint.com

PERL exec Function


Syntax

exec EXPR LIST

exec LIST


Definition and Usage

Executes a system command (directly, not within a shell) and never returns to the calling script, except if the command specified does not exist and has been called directly, instead of indirectly through a shell. The operation works as follows:

  • If there is only one scalar argument that contains no shell metacharacters, then the argument is converted into a list and the command is executed directly, without a shell.
  • If there is only one scalar argument that contains shell metacharacters, then the argument is executed through the standard shell, usually /bin/sh on Unix.
  • If LIST is more than one argument, or an array with more than one value, then the command is executed directly without the use of a shell.

Return Value

  • 0 only if the command specified cannot be executed

Example

Following are the usage...

    exec '/bin/echo', 'Your arguments are: ', @ARGV;
    exec "sort $outfile | uniq";

Another example:
    exec {'/bin/csh'} '-sh';	# pretend it's a login shell


Copyright © tutorialspoint.com