Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Use Perl inside Shell scripts

Submitted by on May 1, 2008 – 11:44 am 2 Comments

Perl is a far more powerful programming tool than any shell script. Sometimes you want to borrow some of that power without having to rewrite your entire shell script. There is an easy way to integrate Perl snippets inside your shell script.

In the following example we encapsulate a Perl script inside of a Korn shell function. The Perl script outputs the value of Perl $email variable. We then assign the value of this Perl variable to a shell variable by executing the function:

#!/bin/ksh
perl_email() {
/usr/bin/perl << 'EOF'
use EmailClient;
my $obj = EmailClient-new;
my $email = $obj-getData( -field = 'email' );
print "$email";
EOF
}
SHELL_EMAIL=$(perl_email)
Print Friendly, PDF & Email

2 Comments »

Leave a Reply to lcollier93sbcglobalnet Cancel reply

%d bloggers like this: