Lately, I have been experimenting with the ps command, and sometimes long paths wrap to the next line (or two) and make it hard to read. I want to pipe the ps output into another program to limit the output to x number of characters.Here is what I have so far, but it doesn't work quite right:ps aux | cut -c1-$(stty size | cut -d' ' -f2)$(stty size | cut -d' ' -f2) evaluates to 167, but doesn't seem to be valid input for cut.Is there a way to get this type of syntax to work in bash?
Dynamically trim stdout line width in Bash
bash;shell;stdout;cut
The following works:ps aux | cut -c1-$(stty size </dev/tty | cut -d' ' -f2)This also works:v=$(stty size | cut -d' ' -f2) ; ps aux | cut -c1-$vThe problem seems to be that stty needs to have the tty on its standard input in order to function.  The above two approaches solve that.There is still another option.  While stty's stdin and stdout are both redirected in the above commands, its stderr is not: it still points to a terminal.  Strangely enough, stty will also work if it is given stderr as its input:ps aux | cut -c1-$(stty size <&2 | cut -d' ' -f2)