I am trying to use the tee command to redirect output to a file, and I want the file to be created in a dir which is yet to be created.
date | tee new_dir/new_file
when new_dir is not there, the tee command fails saying
tee: new_dir/new_file: No such file or directory
If I create the new_dir prior to running the tee command, then it works fine, but for some reason I don't want to create the new_dir manually, is it possible to create the new_dir with the tee command ?
Replace
tee
with a function that creates the directory for you:If you want the function to work when invoked with a simple file name:
Hmm... After some experiments, I've found some interesting things.
First of all, let's try to touch some file:
It works fine. But let's use the same thing with quotes:
So, for my bash function:
after that I changed call from it:
to it (first argument without quotes):
And all is well.
UPDATE
This case considers
.lein
as existing directory.No. You'll have to create the directory before running
tee
.Since it is
tee
command, it simultaneously writes both to thenew_file
and tostdout