tput cols在脚本中无法正常工作 [英] tput cols doesn't work properly in a script

查看:55
本文介绍了tput cols在脚本中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在脚本中使用"tput cols",除非将窗口最大化,否则一切正常.我的脚本能够正确获取任何窗口大小,但是当窗口最大化时,它将获得错误的值(80).然后,我直接在终端中输入"tput cols",然后得到正确的大小(158).所以我的问题是,即使窗口最大化,如何获得正确的值呢?

I'm using "tput cols" in a script everything goes OK except when the windows is maximized. my script is able to get any windows size correctly but when the windows is maximized, it gets a wrong value (80). Then I type "tput cols" directly into the terminal and I get the correct size (158). So my question is, how can I get the right value even when the window is maximized???

预先感谢

推荐答案

tput cols 可能是从shell环境变量 $ COLUMNS 中读取的,而不是从 TIOCGWINSZ中读取的 ioctl.Shell可能会响应 SIGWINCH 更新此变量,但这当然不会影响脚本中的 $ COLUMNS 变量.

tput cols may be reading from the shell environment variable $COLUMNS instead of the TIOCGWINSZ ioctl. The shell is probably updating this variable in response to SIGWINCH, but this of course does not affect the $COLUMNS variable within your script.

尝试取消设置列,并查看 tput cols 是否从终端ioctl中获取值.

Try unset COLUMNS and seeing if tput cols picks up the value from the terminal ioctl.

这篇关于tput cols在脚本中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆