Doing it this way is better as the clear command is executed after the error message "can't access tty" is printed.