Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6220701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:00:10+00:00 2026-05-24T08:00:10+00:00

Why is this exists check returning different results for pwd versus the other examples?

  • 0

Why is this exists check returning different results for pwd versus the other examples? What’s happening here?

[me@unixbox1:~/perltests]> cat testopensimple.pl
#!/usr/bin/perl

use strict;
use warnings;

# |<command> for writing
# <command>| for reading

testopen("| pwd");
testopen("pwd |");
testopen("| hostname");
testopen("| cd");
testopen("| sh");
testopen("| sleep 2");

sub testopen {
        my $command = shift;

        print "Exists: " . (-e $command ? "true" : "false") . "\n";
        print "testopen($command)\n";
        eval {
                open(my $fh, $command) or die "$! $@";
                my $data = join('', <$fh>);
                close($fh) or die "$! $@";
                print $data . "\n";
        };
        if ($@) {
                print $@ . "\n";
        }
}

[me@unixbox1:~/perltests]> perl testopensimple.pl
Exists: true
testopen(| pwd)
/home/me/perltests

Exists: true
testopen(pwd |)
/home/me/perltests

Exists: false
testopen(| hostname)
unixbox1

Exists: false
testopen(| cd)

Exists: false
testopen(| sh)

Exists: false
testopen(| sleep 2)

Update:

I’m not convinced that it’s a shell built-in vs external command issue. Try it with a command like netstat which is external. pwd is the only command I’ve found thus far that returns true on the exists check with pipes.

Update 2:

Through the several iterations of testing I was doing, files named ‘| pwd’ and ‘pwd |’ ended up being created. That explains what I’m seeing. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:00:11+00:00Added an answer on May 24, 2026 at 8:00 am

    -e '| pwd' will only return true if you have a file named | pwd in the current directory.

    -e 'pwd |' will only return true if you have a file named pwd | in the current directory.

    $ perl -E'say -e "| pwd" ? 1 : 0'
    0
    
    $ touch '| pwd'
    
    $ perl -E'say -e "| pwd" ? 1 : 0'
    1
    
    $ perl -E'say -e "pwd |" ? 1 : 0'
    0
    
    $ touch 'pwd |'
    
    $ perl -E'say -e "pwd |" ? 1 : 0'
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is somewhat of a sequel to Slow Exists Check . Alex's suggestion works
I wrote this method to check if a page exists or not: protected bool
can I check if a file exists at a URL? This link is very
In django how to check whether any entry exists for a query sc=scorm.objects.filter(Header__id=qp.id) This
The question here is whether something like this already exists or, if not, whether
I used to write my EXISTS checks like this: IF EXISTS (SELECT * FROM
I have this code snippet inside a function that checks if an object exists
Does a direct way to do this exists? if element in aList: #get the
This question exists because it has historical significance, but it is not considered a
I'm not sure if this even exists or not, so I figured I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.