最近,每当我尝试在笔记本电脑和 PC 之间同步时,Unison 就会出现一些奇怪的错误。我意识到我添加了一行,bashrc
每当我打开终端时,它都会打印待处理的任务。
在我的中添加的行bashrc
:
task list #this command comes from a small utility called taskwarrior
错误在这里:
Received unexpected header from the server:
expected "Unison 2.40\n" but received "\nID Proj Age Description\n-- -------- --- -----------------------------\n 2 11d Do the research work\n 3 Life 11d Get stickynotes from stationary\n 1 Technical 11d Fix the error\n\n3 tasks\n",
which differs at "\n".
This can happen because you have different versions of Unison
installed on the client and server machines, or because
your connection is failing and somebody is printing an error
message, or because your remote login shell is printing
something itself before starting Unison.
正如错误日志中提到的,my login shell is printing something itself before starting Unison
.这确实是问题的根源。
所以,现在我有两个问题:
如何让我的 bashrc 在 Unison 标头之后打印“任务列表”消息?或者,我可以让 ssh 会话加载单独的 RC 文件,以便根本不打印“任务列表”吗?
打印任何东西都安全吗?我的意思是,如果我设法在 Unison 标头之后打印我的任务列表,由于标头中的附加信息,他们在同步期间是否有可能发生数据损坏?
PS:Unison 使用 ssh 进行两个系统之间的通信。
答案1
如果不是,您可以测试脚本的输出(即rc文件)是否是终端;如果是,则输出文本应该是安全的,如果不是终端,则不输出任何内容:
if [ -t 0 ]; then
# check your jobs here and print any info you want to see
fi
答案2
i
您可以通过搜索in来检查当前是否是交互式的$-
:
if expr "$-" : '.*i' >/dev/null; then
echo interactive
fi