Skip to main content
2 of 2
Formatting
jasonwryan
  • 74.8k
  • 35
  • 204
  • 230

Dynamically trim stdout line width in Bash

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?

lentils
  • 133
  • 1
  • 1
  • 6