行号与列在脚本中失去了环境变量 [英] LINES and COLUMNS environmental variables lost in a script
问题描述
考虑以下几点:
me@mine:~$ cat a.sh
#!/bin/bash
echo "Lines: " $LINES
echo "Columns: " $COLUMNS
me@mine:~$ ./a.sh
Lines:
Columns:
me@mine:~$ echo "Lines: " $LINES
Lines: 52
me@mine:~$ echo "Columns: " $COLUMNS
Columns: 157
me@mine:~$
变量 $ LINES
和 $列
是shell变量,不可以环境变量,因此不会导出子进程(但是当我调整xterm窗口,通过ssh从远程位置登录,即使他们会自动更新)。有没有一种方式,我可以让我的脚本知道当前的终端大小?
The variables $LINES
and $COLUMNS
are shell variables, not environmental variables, and thus are not exported to the child process (but they are automatically updated when I resize the xterm window, even when logged in via ssh from a remote location). Is there a way in which I can let my script know the current terminal size?
编辑:
我需要这作为一种解决方法做这个问题:六(以及VIM,少了,类似的命令)弄乱了我每次使用它的时间在屏幕上。修改终端是不是一种选择,因此,我在寻找解决办法(向下滚动 $ LINES
行肯定是不完美的解决方案,但至少是比失去的更好previous屏)
I need this as a workaround do this problem: vi (as well as vim, less, and similar commands) messes up the screen every time I use it. Changing the terminal is not an option, and thus I'm looking for workarounds (scrolling down $LINES
lines surely is not the perfect solution, but at least is better than losing the previous screen)
推荐答案
您可以摆脱线和列的 tput的
#!/bin/bash
lines=$(tput lines)
columns=$(tput cols)
echo "Lines: " $lines
echo "Columns: " $columns
这篇关于行号与列在脚本中失去了环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!