Normally, when you want to redirect (standard) output of a script to a file, you run it with a redirection, like:
$ ./script.sh > out.log
However – you can also accomplish the same from inside the script by using exec. The following will write “Test” and then current time into /tmp/out.log”
#!/bin/bash exec >/tmp/out.log echo Test date
You can find more information about exec on tldp.