Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-08-2011, 11:31 AM   #1
Registered: Apr 2010
Posts: 62

Rep: Reputation: 2
invoking perl inside a ksh script

Can anyone help with this?
Trying to invoke perl inside ksh script.


/bin/perl -e
($second, $minute, $hour) = gmtime($epochseconds);
print sprintf("%02d:%02d:%02d\n", $hour, $minute, $second);

Thanks in advance for your help ..
Old 02-09-2011, 07:20 PM   #2
Senior Member
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Linux Mint
Posts: 1,678

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
On my system:
~$ which perl
perhaps you too need to be looking in /usr/bin rather than in /bin
Old 02-09-2011, 07:39 PM   #3
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Originally Posted by cheltz View Post
Can anyone help with this?
Trying to invoke perl inside ksh script.


/bin/perl -e
($second, $minute, $hour) = gmtime($epochseconds);
print sprintf("%02d:%02d:%02d\n", $hour, $minute, $second);

Thanks in advance for your help ..

You're not saying in which way this fails, but one problem
is that the '' that normally wrap a '-e' command are missing.


/bin/perl -e
($second, $minute, $hour) = gmtime($epochseconds);
print sprintf("%02d:%02d:%02d\n", $hour, $minute, $second);'
Note: I never tried a perl command in that way within a script.

Old 02-09-2011, 11:29 PM   #4
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 731

Rep: Reputation: 75

#!/usr/bin/env bash

# @(#) s3	Demonstrate perl script embedded in shell script.

# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }

perl -e '
print " Hello, world from perl in a continued line.\n";

perl  <<'EOF'
print " Hello, world from perl in a here document.\n";

# Be careful placing additional shell code here.

exit 0
 Hello, world from perl in a continued line.
 Hello, world from perl in a here document.
Best wishes ... cheers, makyo
Old 02-09-2011, 11:54 PM   #5
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 156

Rep: Reputation: 44
This is for awk (nawk) but equally valid for perl, sed, etc...

The normal way is to use Single Quotes....

nawk '# output to mailx commands!
/^[^ ]/ { recipent=$0; }
/^ / { print $0 > "|mailx -s \"This is the test\" " recipent; }
/^$/ { close( "|mailx -s \"This is the test\" " recipent );
' list.txt

Note the whole script is inside single quotes on the nawk command line!

ASIDE: old versions of awk must have something on the first line thus the
addition of the # comment to keep it happy! Perl needs no such comment but
does require a -e option to execute a command line argument.

To insert a external shell variable into the script you need to close
the single quotes, output variable and re-open the single quotes. Also
the variable sould be in double quotes so as to prevent any insertion of
space characters, and depending on situation double quotes inside the
awk script too.

Example inserting a $prefix shell variable into a awk string.
' ...
{ print "'"$prefix"'" $0; }
... '

Also to insert a single quote into the script you have to also exit the
wrapping single quotes and supply it outside those quotes
' ...
{ print "I just can'\''t do that!"; }
... '

CAUTION: Watch for single quotes inside any COMMENTS which is in the script!
Comments are within the single quotes so are also scanned for those quotes.

I have used that technique to wrapper very large perl scripts inside even larger shell scripts.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
invoking windows command inside a shell script nano2 Programming 6 09-09-2009 04:46 AM
linux command inside perl script von_vea Programming 5 09-08-2009 02:54 PM
mv inside ksh script problem katkota Linux - Newbie 2 01-14-2009 09:01 AM
perl inside a shell script baidym Linux - Newbie 2 05-05-2008 07:42 PM
calling a c++ binary inside a perl script Blue_muppet Programming 3 08-29-2004 12:31 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration