How to redirect standard input and output with Bash

bash, io

Solution

The most likely explanation is that the output you're seeing is from `stderr`, not `stdout`. To redirect both of them to a file, do this:

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

or

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

Problem

``` #!/bin/bash ./program < input.txt > output.txt ``` The `> output.txt` part is being ignored so output.txt ends up being empty. This works for the `sort` command so I expected to also work for other programs. Any reason this doesn't work? How should I achieve this?

Original source