0

I have a bash for loop that looks like this:

for entry in ~/properties/*  
do
  PROP=$(basename "$entry")
  echo $PROP
  my_converter $entry -o $OPATH$PROP.vcl --tf --tf-file=$OPATH$PROP.tf
done

This does most of what I need. I set the OPATH variable before the loop and create a new file with the same name and append a different file extension.

What's missing is to write the output generated by running my_converter into another file with the same name but with a file extension of .info.

Some things I've tried (based on this question):

my_converter $entry -o $OPATH$PROP.vcl --tf --tf-file=$OPATH$PROP.tf >> $OPATH$PROP.info

and creating a new file descriptor with the .info file as the target:

  ...
  do
    exec 3>$entry.info
    PROP=$(basename "$entry")
    echo $PROP
    my_converter $entry -o $OPATH$PROP.vcl --tf --tf-file=$OPATH$PROP.tf 1>3
  ...

And for completeness, I've also tried just doing a regular redirect:

my_converter $entry -o $OPATH$PROP.vcl --tf --tf-file=$OPATH$PROP.tf > $OPATH$PROP.info

I know there's some redirect voodoo I can do to get this working. Any help greatly appreciated.

8
  • 1
    If you want to redirect to a pre-opened file descriptor, it should be >&3; just 1>3 opens a file named 3. Commented Dec 9, 2020 at 16:57
  • That said, there's no reason you can't just use >"$entry.info". Commented Dec 9, 2020 at 16:58
  • Can you build a minimal reproducible example that doesn't require tools (like my_converter) and file/directory structures (~/properties) that only you have, so others can see the problem themselves and test proposed answers? Commented Dec 9, 2020 at 16:58
  • creating a minimal reproducible example is proving a bit difficult. I'm not sure why exactly but everything else I'm doing write the output to the file as expected. For everything I've tried to make an MRE I've been using a linux command (on my mac). I'm not sure it matters but my_converter is a ruby application. When I use the standard > output.file on the commandline running the app for a single conversion it works just fine. Commented Dec 9, 2020 at 17:14
  • 1
    Yeah looks like I just needed some double quotes and to clean up my input and output directories to see the changes. Thanks for the help @CharlesDuffy! Commented Dec 10, 2020 at 19:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.