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 7858841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:37:34+00:00 2026-06-02T21:37:34+00:00

I have a script that runs in AIX ksh that looks like this: wc

  • 0

I have a script that runs in AIX ksh that looks like this:

wc dir1/* dir2/* | {awk command to rearrange output} | {grep command to filter more} > dir2/output.txt

It is a precondition to this line that dir2/output.txt does not exist.

The issue is that dir2/output.txt has contained itself in the output (it’s happened a handful of times out of hundreds of times with no problem). dir1 and dir2 are NFS-mounted.

Is it related to the implementation of wc — what if the the first parameter takes a long time? I think not, as I’ve tried the following:

wc `sleep 5` *.txt > out.txt

Even in this case out.txt does not list itself.

As a last note, wildcards are used in this example where they are used in the actual script. So if the expansion happens first, why does this problem occur?

At what point is dir2/output.txt actually created?

  • 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-06-02T21:37:35+00:00Added an answer on June 2, 2026 at 9:37 pm

    Redirections are done by the shell, as are globs. Your problem is that, in the case of a pipeline, each pipeline stage is a separate subprocess; whether the shell subprocess that does the final redirection runs before the one that builds the glob of input files for wc will depend on details of the scheduler and system load, among other things, and should be considered indeterminate.

    In short, you should assume that this will happen and either exclude dir2/output.txt (take a look at ksh extended glob patterns; in particular, something along the lines of dir2/!(output.txt) may be useful) or create the output somewhere else and mv it to its final location afterward.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that runs this command: system(pdftohtml -i -noframes /home/myacc/pdfs/test.pdf); When
I have a bash script that runs (something like) the following command: vim -E
I have a command-line PHP script that runs a wget request using each member
I have a script that runs with root privileges, and I have a command
I have this particular script that runs so that the flash elements don't show
I have a script that runs on the command line, called by a crontab.
I have a script that repeatedly runs an Ant buildfile and scrapes output into
I have a script that runs recursively over many directories, and I'd like to
I have a PHP script that runs as a background process. This script simply
I have a script that runs every two minutes for a Tweet-getter application. In

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.