Share your knowledge at the LQ Wiki.
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 03-15-2012, 02:55 AM   #1
LQ Newbie
Registered: Mar 2012
Posts: 4

Rep: Reputation: Disabled
check output of command in perl

Hello all,

I've an existing shell-script, but I would like to rewrite it in Perl. I'm new to Perl and now I stumble on something. In my shell-script I have the following line:
if [ a`/usr/well561/bin/newlogfile 1` = aY ]; then
echo "true"
echo "false"

How should I rewrite the above in Perl. I've tried several things but the don't work, mostly an error on Bareword "Y".

Advise please

Thanx Kluther
Old 03-15-2012, 10:16 AM   #2
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
I haven't seen the syntax that you have in the 'if' command before (namely the 'a' before the command, and the 'Y'). What does it do?

Is the code snippet meant to check the output of the newlogfile command, and see if it returns 'Y'?

If so, the following code should work:

if( `/usr/well561/bin/newlogfile 1` eq "Y\n"){
    print "True\n";
} else {
    print "False\n";
(or if newlogfile doesn't output a newline as well, then change "Y\n" to "Y")

Hope this helps,
Old 03-15-2012, 10:28 AM   #3
LQ Newbie
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you Snark1994,

this is it. I also saw what went wrong. The program /usr/well561/bin/newlogfile returns a newline.

Thank you very much for your help!

Old 03-15-2012, 08:51 PM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Another way would be
$result = `/usr/well561/bin/newlogfile 1`;
if( $result eq 'Y' )
In general, get returned 'stuff', then tidy it up, then check what's left.
It's more robust.
Good Perl docs etc


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
[SOLVED] Assigning Output of a Command to an Array in Perl devUnix Programming 10 11-27-2010 06:43 PM
How to redirect the output of exec command output in perl? sudhap85 Linux - Newbie 3 08-28-2009 04:35 PM
Perl: Running Command line apps in background and capturing output s0l1dsnak3123 Programming 8 03-28-2008 02:24 PM
Perl - how to capture output of a command with more than one args new_2_unix Linux - Newbie 2 11-29-2007 11:55 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:22 PM.

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