I'm writing a very simple bash script that concats two files together and saving output into a log file
#!/bin/bash
file1="/srv/users/test/foo.txt"
file2="/srv/users/test/bar.txt"
newFile="/srv/users/test/foobar.txt"
logFile="/srv/users/test/log.txt"
echo "making file" >> $logFile
echo `date` >> $logFile
cat $file1 $file2 > $newFile 2>> $logFile
echo "finished making file" >> $logFile
But the problem is that if newFile does not exist, then an error is printed to the display rather than to the log file.
How can I make it so the error is printed to the log file instead of the display?
Thanks!
date >> $logfile..then an error is printedPlease post the exact error message. Ifnewfiledoes not exists, the>should create it, unless the directory does not exists./usr/bin/combineCerts: line 11: /absolute/path/foobar.txt: No such file or directory