我注意到 mysql 选择/命令的输出格式很好,超出了默认终端列集 (80),我只需调整终端窗口大小即可查看 1 行中的所有列。如何配置?我正在使用 HERE 文档,其注释长度超过 80 个字符,然后将其传递到 SSH 会话(我不介意稍后在输出中看到它们),但不是扩展到行,而是在 81. 位置上的字符,然后继续覆盖我的提示时的登录名如下:
这是我的脚本:
#!/bin/bash
ssh -A -tt -l user1 192.168.1.10 <<ABC
#-----------------------------------------------------
#comments are very useful for explaining what does your code actually do. And sometimes they can be very long.
#-----------------------------------------------------
some_command
exit
ABC
这是我的输出:
[user@server ~]$ #-----------------------------------------------------
actually do. And sometimes they can be very long.explaining what does your code
[user@server ~]$ #-----------------------------------------------------
编辑
预期结果:
[user@server ~]$ #-----------------------------------------------------
[user@server ~]$ # comments are very useful for explaining what does your code actually do. And sometimes they can be very long. Even over 80 characters.
[user@server ~]$ #-----------------------------------------------------
知道如何避免吗?
答案1
您正在强制tty
分配(ssh -tt
),但我敢打赌终端的尺寸设置不正确(可能没有尺寸)。假设您确实需要该选项,您可以使用设置终端尺寸的行-tt
来启动脚本:stty
#!/bin/bash
ssh -A -tt -l user1 192.168.1.10 <<ABC
stty $(stty size | sed 's/ / cols /;s/^/rows /')
#-----------------------------------------------------
#comments are very useful for explaining what does your code actually do. And sometimes they can be very long.
#-----------------------------------------------------
some_command
exit
ABC
在这里,我们stty
使用终端的实际大小构建一个命令。如果您当前的终端是 80x25,stty size
将产生25 80
,并且在替换后,生成的命令将为stty rows 25 cols 80
.