The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace aword in a.The replaced word should not be overwitten in perl(details inside) madhul2002 Shell Programming and Scripting 7 02-21-2009 08:10 PM
doing grep inside perl file bp_vardhaman Shell Programming and Scripting 5 09-08-2008 06:43 AM
Run the command inside perl script vinay123 Shell Programming and Scripting 1 06-13-2008 11:01 AM
calling a C executable from inside a Perl script mark_nsx Shell Programming and Scripting 3 10-07-2005 06:49 AM
Perl log parcer. (for custom logs details inside) Optimus_P Shell Programming and Scripting 1 08-30-2002 06:13 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-25-2009
SaadLive SaadLive is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
Using Perl Inside KSH

Hi there,

I am new to Perl and KSH. The system I am using picks up the KSH scripts and uses them in a batch job control system.

I am trying to set a variable from a perl command


Code:
#!/bin/ksh -eaxp
#*******************************************************************************
# Testing Program
#*******************************************************************************
#+
#job "TEST":U*


#-

$time='perl -e 'print localtime();''

I cannot figure out how to make KSH capture the output of Perl scripts. Anyone have any insight on this?

Thank you in advance, I know how annoying these questions can be.
  #2 (permalink)  
Old 09-25-2009
varontron varontron is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 110
you need to use backticks (i.e. ` ,on the tilde key, most likely) around your perl command, not single quotes, and remove the $ when you set the var, like so:


Code:
time=`perl -e 'print localtime();'`

then you can ref the var with $ like in 'echo $time'
  #3 (permalink)  
Old 09-28-2009
SaadLive SaadLive is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
My problem now is pass variables this way.


Code:
typeset -Z4 Var
Var=1234
rm -rf myfile
perl -e -'open (POSTSET, ">myfile");
print POSTSET $Var;
close (POSTSET);'

Perl never gets that variable $Var. How do I pass Perl the variable from KSH?

Thanks.

Last edited by Franklin52; 10-02-2009 at 04:36 AM.. Reason: Please use code tags!
  #4 (permalink)  
Old 09-28-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813

Code:
perl -e -'open (POSTSET, ">myfile");
print POSTSET $ARGV[0];
close (POSTSET);'  "$var"

Start with the above. You do know the shell can write to a file more efficiently than invoking perl like that?
  #5 (permalink)  
Old 09-28-2009
varontron varontron is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 110
all shell variables are stored in the $ENV hash built in to perl.

to access:

Code:
perl -e -'open (POSTSET, ">myfile");
print POSTSET "$ENV{Var}"
close (POSTSET);'

That being said, unless this is just sample code, as Jim pointed out, perl does seem like overkill here.
  #6 (permalink)  
Old 10-01-2009
adderek adderek is offline
Registered User
  
 

Join Date: Sep 2007
Location: Poland
Posts: 111
Hint:

Code:
#!/bin/env ksh
/bin/env perl run_my_perl_script_that_does_everything_and_forget_about_shell.pl


Last edited by Franklin52; 10-02-2009 at 04:37 AM.. Reason: adding code tags
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0