I have a simple script
echo "Some Text"
echo " "
compgen -c a | sort | uniq | column
echo " "
This line set is repeated for each letter of the alphabet (not set in a loop) in 1stscript.sh.
I have a second lessscript.sh.
1stscript.sh | less
Running 1stscript.sh by itself fills the entire width of my terminal emulator:
But running lessscript.sh or 1stscript.sh | less directly only uses about 1/3 of my terminal emulator's width:
aa-exec apropos atrm
ab apt aubrsync
aclocal apt-cache aubusy
I have tried commenting out set text length lines. I have tried flags with column such as t and x to no avail.
How can I make it adapt to my terminal width in both cases?
columnwill try to find the size of the terminal it's writing to, but if it's writing to a pipe (which has no inherent width), it defaults to 80.The program
tputdoes the same, but in addition to output, it checks stdin, stderr, and the session TTY. You can therefore use that to determine the column count forcolumn: