If a simple return does not do the job, here is another approach taken from this blog article :
if `tty -s`; then mesg n fi
tty -s checks for TTY ( -s tells it to silently do this and simply exit with the appropriate return code). tty returns the tty binding (for example, "/ dev / pts / 1"). This should be safer than checking for some shell variable;)mesg controls write access to your terminal ( msg n prohibits writing to (in our case, nonexistent) terminal), and therefore it is required to be present.
On some systems (in my case, Debian Jessie, but there are also reports on Ubuntu) mesg n 1 is installed unconditionally in either ~/.bashrc or ~/.profile . Therefore, if it exists in this way, it could be a criminal.
As in other examples, you can, of course, do one-line: [[ $(tty -s ) ]] && mesg n . And no one bothers you to combine the two:
if [[ $(tty -s ) ]]; then mesg n else return fi
Btw: according to a related article, this snippet should go to the .bashrc device you are connecting to ("remote"), so if it is johndoe@somehost , this should be applied at the beginning of /home/johndoe/.bashrc on somehost . In my case, I just got rid of the message after I applied this change to the “calling host”.
PS: Also check .profile if it has a standalone msg n command (this was in my case). If so, wrap it there.
1: mesg n used so that other users on the machine write to your current terminal device, which in itself is good, but not useful for some rsync job;)
Zzy
source share