Fork me on GitHub

Linux命令——mesg

参考:图解Linux命令之--mesg命令

Linux mesg命令

前言

在看一个脚本~/.profile 的时候发现了mesg命令以及一个奇怪用法

~/.profile 

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n || true
View Code

meag命令

语法

mesg [ny]

功能

用来设置当前终端的写权限,即是否让其他用户向本终端发信息

参数

n 不允许其他用户将信息直接显示在你的屏幕上。

y 允许其他用户将信息直接显示在你的屏幕上。

演示

 1) 如果mesg n设置为n的话,用write,talk命令时,会显示write permission turned off提示

 2) 两个终端通过write命令发送讯息的过程

mesg n || true中 || true啥意思?

参考:What does the || true do in the mesg command do?

It forces the whole expression to exit with a success status: The operator "||" means the command to the right is only executed if the command beforehand exited with a "failure status" (exit code != 0). The "true" command does nothing but exit with exit code 0 which means "success".

简单翻一下

mesg n || true可以保证这句话退出状态是success。只有当||前面那句话执行失败,即mesg n 执行失败时,||后面才会执行。相当于||前面那句话退出码!0,现在变成0.

 

 

posted @ 2018-10-16 22:55  克拉默与矩阵  阅读(2369)  评论(0编辑  收藏  举报