Perl - Command assingment to variable.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl - Command assingment to variable.
# 1  
Old 04-19-2009
Perl - Command assingment to variable.

Hi

How do i assign the output of a unix command to a variable ? say i want the whoami output to be assigned to a variable?

Thanks
# 2  
Old 04-19-2009
you can use backticks, system() or open(). please see the docs.
# 3  
Old 04-19-2009
system will not return results back to the perl program, but backtiks `` or the more readable version of backtiks qx{} can be used.

$whoami = qx{whoami};
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Shell Script Assingment!

Q 1. Write a shell script to print the following pattern upto n (specified by user)- @ @@ @@@ @@@@ @@@ @@ @ Please help! :) (1 Reply)
Discussion started by: heatedline
1 Replies

3. 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

4. Shell Programming and Scripting

Perl command to replace path part of variable

I'm trying to replace path which is part of variable inside script file: FROM: ABC_HOME=$ABC_ROOT/abc/1.0 TO: ABC_HOME=$ABC_ROOT/abc/1.5 I'm using this: perl -pi -e 's\ABC_HOME=$ABC_ROOT/abc/1.0\ABC_HOME=$ABC_ROOT/abc/1.5\g' /apps/scripts/test.sh This command is not working because... (2 Replies)
Discussion started by: djanu
2 Replies

5. Shell Programming and Scripting

Passing perl variable to shell command

Can we pass perl variable to shell commands. If yes, please give some example. (2 Replies)
Discussion started by: Anjan1
2 Replies

6. Shell Programming and Scripting

Perl System command calls to variable

I am new to scripting in Perl so I have a dumb question. I know I can call system commands using system("date"); But I am not able to: 1. set its output to a variable 2. run in quiet mode(no output to the screen) The examples i have #!/usr/bin/perl print `date +\%y\%m\%d.\%H\%M`;... (5 Replies)
Discussion started by: 4scriptmoni
5 Replies

7. 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

8. UNIX for Dummies Questions & Answers

need help for an assingment

i have to do an assingment using mailx, where can i find info on mailx? *yes i read the rules, so i am not asking for the asnwers, just need to learn about mailx more (1 Reply)
Discussion started by: punk_87
1 Replies

9. Shell Programming and Scripting

Query string assingment for other variable in PERL

Hi friends, I want to use query string value to another variable but it gives following error when I use it with print out command, Insecure dependency in open while running with -T switch at C:/Program Files/Apache Group/Apache2/cgi-bin/cdr_findere.pl line 119. My code as follows, my... (0 Replies)
Discussion started by: maheshsri
0 Replies

10. Shell Programming and Scripting

perl variable assingment

I want to assign the current user to a variable in my perl script. My first attempt using Solaris 8 (perl 5) is: $VAR = system(logname); However, this assigns 0 to $VAR, and outputs the user to the screen. Does anyone know the command that I need? Thanks, seismic_willy (2 Replies)
Discussion started by: seismic_willy
2 Replies
Login or Register to Ask a Question