Possible duplicate
Hello,
I'm struggling with output redirection within a bash for loop. I have several similar bash scripts, each scripts being launched on a different input file. The scripts called a tool with a few arguments.
The bash scripts are like this :
my_tool --input input_file --arg1 arg1_name --arg2 arg2_name > output_dir/result_X.dat
X being a string which is unique for each script.
I run all of them in a for loop :
for script in scripts_dir/*.sh
do
bash $script
done
However, the stdout of each run still display on the terminal. The specified output files are created, but empty. How I can solve that ? I found other questions on stackoverflow where the answer is a redirection of the full loop in one big output file, but I'd like to avoid that.
If I replace > output_dir/result_X.dat by > /dev/null : the standard outputs display on the terminal
If I replace > output_dir/result_X.dat by ` 2> /dev/null : nothing is displayed.
Thanks in advance.
an_identifier_defined_in_the_script.dat? The shell parses that line before the script is even executed, so if you are trying to define the name of the output file in the script, this will not work.2>&1says redirect stderr to stdout. You could equally put2>output/result_X.dat