0

My goal is to write a script that will redirect the output of a bash command to a new folder. The command I am utilizing generates an output that consists of several different files and file types, some folders etc.. I am relatively new to this, and am confused because when I wish to output I know hot to do it when it is something simple such as this:

echo "blah blah" > /some/location/file.txt

But where I run into trouble is trying to redirect multiple different things with unknown names. (i.e. in the example above if I didn't know the output should be titled file.txt or even that its text) help is much appreciated

1
  • multiple output going in same file? use the answer below + think about replacing > with >> Commented Apr 22, 2014 at 18:44

2 Answers 2

1

The word following > undergoes the usual expansions, so you can write code like

output_file=/some/location/file.txt

echo "blah blah" > "$output_file"

and it will work, regardless of the value of output_file.

Sign up to request clarification or add additional context in comments.

2 Comments

I didn't understood the question so far. Did you? :)
Wild guess :) The comment "... or even that its [sic] text" makes me think the concern is that the code will run under windows, so the file extension used is significant, and so the file name needs to be generated dynamically and correctly.
0

If the command you are running is generating multiple files with a relative path to the current working directory, the the easiest way to handle it is to create a separate directory and run it from there.

For example, if you wanted to run the command 10 times and not have the files clobber each other, you could do this:

for run in `seq 1 10`; do mkdir $run; pushd $run; mycommand; popd; done

This would create ten directories and the command would presumably put its output into the directory it is running in.

Comments

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.