Passing perl variable to shell command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing perl variable to shell command
# 1  
Old 03-27-2011
Passing perl variable to shell command

Can we pass perl variable to shell commands. If yes, please give some example.
# 2  
Old 03-27-2011
How about this: get a variable named var in perl into PERL_VAR:

Code:
PERL_VAL=$(perl -e 'my $var="200" ; print $var')

Or did you mean somthing like this
Code:
my $file1="source";
my $file2="dest";
 
system("/usr/bin/cp", $file1, $file2);

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 03-27-2011
Thanks for the reply.

But i want to use in open().

Code:
open(PS,"cmd  |") || die "Failed: $!\n";

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variable from bash to perl script

Hi All, I need to pass a variable from bash script to perl script and in the perl script i am using those variables in the sql query but its giving error : Use of uninitialized value $ENV{"COUNTRYCD"} in concatenation (.) or string at /GIS_ROOT/custom/tables/DBread_vendor.pl line 50. Can ... (6 Replies)
Discussion started by: NileshJ
6 Replies

2. Shell Programming and Scripting

Passing variable into perl system commands

Hi guys, I'm having issues getting the following snippet of my script to work and was hoping for some suggestions. I'm trying to pass a variable in perl system with wget. This is what I need help with: #!/usr/bin/perl use strict; use warnings; use POSIX qw(strftime) ; my... (3 Replies)
Discussion started by: timj123
3 Replies

3. Shell Programming and Scripting

Usage of shell variable in perl command

Hi, I have a shell script, In which i have variable "var1" and some perl command inside shell script. export var1='coep -n rst-a2p-hinje.vci.all.com -c' perl -pi -e 's/^/coep -n rst-a2p-hinje.vci.all.com -c /' command.txt currently I am adding value of var1 in command.txt file by... (2 Replies)
Discussion started by: rakeshtomar82
2 Replies

4. Shell Programming and Scripting

Passing Shell variable from file to another command

Hi all, I have a file looks like AAAA 111 BBBB 222 CCCC 333 need to pass variable value like var1=AAAA and var2=111 to another command for three times with next values. stuck over here cat file | while read line do export var1=`awk '{print $1}'` echo $var1 export var2=`cat file... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

5. Shell Programming and Scripting

Use shell variable in perl command line

Hi, I would like to use a shell variable $amp in my perl command line. for fa in $WORKSPACE/*.fa; do amp=`grep ">.*" $fa | sed -e's#>\(.*\)#\1#g'` ampsam="$WORKSPACE/$base/$base.$amp.sam" sqheader=`grep "^@SQ.*SN:$amp.*" $sam` printf "$sqheader\n" >> $ampsam ... (3 Replies)
Discussion started by: jdilts
3 Replies

6. Shell Programming and Scripting

Passing awk variable in perl -e call

Hi. I am on a Solaris box and have an awk script which calls perl via the command line: timeTester="'"`perl -e 'use Time::Local;my $time = timelocal(10,10,10,10,10,2011 );print $time'`"'" But I want to pass awk variables into this call. These are the example awk variables: secondField = 10... (0 Replies)
Discussion started by: pedro6994
0 Replies

7. Shell Programming and Scripting

PERL script -- calling 'sed' by passing 'variable value'.

Hi Friends, I'm calling 'sed' command inside one perl script, which is to list directory names which are having some date value as their names (in the form YYYYMMDD) with in the range (start and end date). #!/usr/bin/perl -w use strict; use warnings; my $DATA = "/export/home/ganapa"; my... (5 Replies)
Discussion started by: ganapati
5 Replies

8. UNIX for Advanced & Expert Users

Passing Hash variable in to sql query in perl

Hi Everyone, Can anyone help me how do i call hash variable in to sql query in perl. Please see the script below i have defined two Hash %lc and %tab as below $lc{'REFF'}='V_RES_CLASS'; $lc{'CALE'}='V_CAP_CLASS'; $lc{'XRPD'}='V_XFMR_CLASS'; $tab{'V_RES_CLASS'}='V_MFR_SERS';... (6 Replies)
Discussion started by: jam_prasanna
6 Replies

9. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

10. Shell Programming and Scripting

Passing variable to perl

I need a non-perl (bash) way to strip the path from a list of "find" results. Below is the perl version which I could use, if I could figure out how to call the script with a variable (like in sh, $1 is the variable passed in ./script variable) $file = "/path/to/file.txt"; # How do I... (2 Replies)
Discussion started by: TheCrunge
2 Replies
Login or Register to Ask a Question