I have a bash script that calls a function. The function, amongst other things, executes a pipeline that sinks its output. To simplify it, here is a contrived example:
#!/bin/bash
func() {
ls "$@" | sort | rev > /tmp/output
}
func "$@"
You would then do something like this to run it. It would do its stuff and deliver its payload to a file. There is no output to the screen.
$ ./myscript .
Now, say I want the output of sort on standard output. How would I do that?
I can achieve it like this:
ls "$@" | sort | tee /dev/tty | rev > /tmp/output
However, using /dev/tty is wrong, because this won't work:
$ ./myscript > myfile
Is there a more correct way to refer to the standard output of a bash script from within a pipleine inside a function ?
(I am using bash 4.3.0 on Arch Linux)