You don't show where the value that ends up in $log1 comes from originally, but I'll bet you need to chomp it to remove a newline. If $log1 ends in a newline, then you're really passing two separate commands to system, an fgrep and a redirection of nothing.