A tool to automatically log in to the server with the teraterm macro and collect logs is created.

I'm worried about test items.

Echo $? for all commands
To get the return value.

What I'm thinking about now is an error that is actually possible (for example, making a directory non-deletable with chattr + i and making it an rm error)
Is generated for each command.

But the macro file is echo $? I thought that it would be better to make the test item to display an error message and the error code that you set yourself, by making the return value of non-zero and determining that it ended abnormally.

But if you do, echo $? Since it is done in the subroutine that the error is judged by comparing the result of 0 with 0, it is necessary to create a macro file for testing for each command.

Which is better? Also, if you have any other good way, I would appreciate it.