How to redirect standard input and output using Bash

#!/bin/bash
./program < input.txt > output.txt

The part is > output.txtignored, so output.txt ends up empty.

This works for the team sort, so I expect it to work for other programs as well.

For what reason does this not work? How do I achieve this?

+5
source share
1 answer

The most likely explanation is that the conclusion you see is from stderr, not stdout. To redirect both of them to a file, follow these steps:

./program < input.txt > output.txt 2>&1

or

./program < input.txt &> output.txt
+6
source