【问题标题】:Is there a way to retain responsive number of columns piping through less?有没有办法通过更少的管道来保持响应的列数?
【发布时间】:2021-02-19 13:12:10
【问题描述】:

我有一个简单的脚本

echo "Some Text"
echo " "
compgen -c a | sort | uniq | column
echo " "

对于1stscript.sh 中的每个字母(未在循环中设置)重复此行集。

我还有第二个lessscript.sh

1stscript.sh | less

单独运行 1stscript.sh 会填满我的终端模拟器的整个宽度:

但是直接运行lessscript.sh1stscript.sh | less 只使用了我终端模拟器宽度的大约 1/3:

aa-exec         apropos         atrm
ab              apt             aubrsync
aclocal         apt-cache       aubusy

我尝试注释掉设置的文本长度行。我尝试过使用column 的标志,例如tx,但无济于事。

如何让它在这两种情况下都适应我的终端宽度?

【问题讨论】:

    标签: bash shell less-unix


    【解决方案1】:

    column 将尝试查找它正在写入的终端的大小,但如果它正在写入管道(没有固有宽度),则默认为 80。

    程序tput 做同样的事情,但除了输出之外,它还检查stdin、stderr 和会话TTY。因此,您可以使用它来确定 column 的列数:

    echo "Some Text"
    echo " "
    compgen -c a | sort | uniq | column -c "$(tput cols)"
    echo " "
    

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 1970-01-01
      • 2021-08-04
      • 2019-09-28
      • 2020-09-04
      • 2022-06-16
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多