Sponsored Content
Full Discussion: Perl command modification
Top Forums Shell Programming and Scripting Perl command modification Post 302922521 by Aia on Saturday 25th of October 2014 10:51:36 PM
Old 10-25-2014
Quote:
Originally Posted by SkySmart
Code:
my $uname = ( -e '/usr/bin/uname' ) ? '/usr/bin/uname' : '/bin/uname';
my $os = ( `$uname 2>/dev/null` );

when i run this code, it seems to be complaining about the backticks. is there any efficient way i can get rid of the backticks and still be able to run the command and assign its value to the variable $os???
It would be interesting to know what kind of backticks complains you get. The posted snippet should work exactly what you want.
You could remove the 2>/dev/null out of it since the backtick captures only the STDOUT by default and ignores the SDTERR

Also, you can remove the backticks if you use qx.
e.i
Code:
my $os = qx{$uname};

The most common ways of executing external commands:
There are some examples in that site and some more explanations.

A synopsis found in that link:
  1. system(): you want to execute a command and don't want to capture its output
  2. exec: you don't want to return to the calling perl script
  3. backticks: you want to capture the output of the command
  4. open: you want to pipe the command (as input or output) to your script
This User Gave Thanks to Aia For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

command for modification date of a file

Good morning, I would like to find all files of a certain type and display their name as well as their modification date. In order to do this, I would do the following: find ./ -name *.csv | ???????? My question: what to put after the pipe instead of the question marks? Is there a basic... (5 Replies)
Discussion started by: scampsd
5 Replies

2. Shell Programming and Scripting

Need help with a slight modification to my PERL script

Hi all, So I have a script that reads a file called FILEA.txt and in that file there are several columns. The ones that are most important are the $name $start and $stop. So currently the script takes values between the start and stop (inside) by using a program called fastamd. But what I... (4 Replies)
Discussion started by: phil_heath
4 Replies

3. Solaris

Command for checking modification history on file

What is the command for checking modification history on file? ---------- Post updated at 01:20 PM ---------- Previous update was at 12:35 PM ---------- Let me rephrase this. On a regular Unix file can I at least check to see the time and date history modification of the file? (6 Replies)
Discussion started by: jastanle84
6 Replies

4. Shell Programming and Scripting

Excel sheet modification using perl module

Is there any possibility to move the content from one cell to another cell (Excel sheet) using perl module? (3 Replies)
Discussion started by: kavi.mogu
3 Replies

5. Shell Programming and Scripting

Excel sheet modification using perl module

I need to insert new column to already existing file ..can any one help me..?? (6 Replies)
Discussion started by: kavi.mogu
6 Replies

6. Shell Programming and Scripting

Excel sheet modification using perl module

Hi , Is there any possibility to read excel sheet in column by column order ?...Thanks in advance,........ :confused: (1 Reply)
Discussion started by: kavi.mogu
1 Replies

7. Programming

Excel sheet modification using perl module

Hi , can any one tell me,"How to extract the same format from existing excel file to new excel file " using Spreadsheet::WriteExcel or Spreadsheet::ParseExcel module ??? Example_pgm: Below program is used to read existing excel file..In this program "my $cell = $_;" line is used to... (0 Replies)
Discussion started by: kavi.mogu
0 Replies

8. Shell Programming and Scripting

Modification to awk command

i have a php file that has this: php.code #!/usr/bin/php <?php phpinfo(); hlight_file(__FILE__); ?> I want my awk code grab whatever is inbetween and including the "<?php" and "?>". Then, it should scan all the entries between these two points. And if the entries between these... (10 Replies)
Discussion started by: SkySmart
10 Replies

9. Shell Programming and Scripting

Help with command modification

Hello folks; I'm using the following command to get the highest number of requests per second in a log file and it works well. grep "2017-02-22" "LogFile.log" | cut -c1-20 | uniq -c | sort -n | tail -n1 Now i would like to also get the smallest requests per second and the amount of time... (5 Replies)
Discussion started by: Katkota
5 Replies

10. Shell Programming and Scripting

Modification of perl script to split a large file into chunks of 5000 chracters

I have a perl script which splits a large file into chunks.The script is given below use strict; use warnings; open (FH, "<monolingual.txt") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">part$i.log") or die "Could... (4 Replies)
Discussion started by: gimley
4 Replies
UNAME(1)						      General Commands Manual							  UNAME(1)

NAME
uname - display information about the system SYNOPSIS
uname [-amnrsv] DESCRIPTION
The uname command writes the name of the operating system implementation to standard output. When options are specified, strings repre- senting one or more system characteristics are written to standard output. The options are as follows: -a Behave as though the options -m, -n, -r , -s, and -v were specified. -m Write the type of the current hardware platform to standard output. -n Write the name of the system to standard output. -r Write the current release level of the operating system to standard output. -s Write the name of the operating system implementation to standard output. -v Write the version level of this release of the operating system to standard output. If the -a flag is specified, or multiple flags are specified, all output is written on a single line, separated by spaces. The uname utility exits 0 on success, and >0 if an error occurs. SEE ALSO
sysctl(8), sysctl(3), uname(3) HISTORY
The uname command appeared in 4.4BSD. STANDARDS
The command is expected to conform to the IEEE Std1003.2 (``POSIX'') specification. 4th Berkeley Distribution February 4, 1995 UNAME(1)
All times are GMT -4. The time now is 04:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy