From experimenting, it seems that even when using ps aux | grep ...
the output depends on the terminal size. This seems seriously weird for me.
Isn't a pipe supposed to make command's output behave in a predictable way?
For example ls
does all fancy formatting magic when run on its own, but when run like ls | less
it always returns the same output styling.
But unlike ls, the output from ps aux | less
cuts the lines to terminal width on FreeBSD (on bash at least). From my brief experimenting, the same command always outputs full length lines in Linux when used with pipes.
Why is this happening and how can I fix it?
Is this just a really weird FreeBSD default? From my understanding this "feature" would make it almost impossible to write reliable bash scripts on FreeBSD as the output of simple piped commands would not be reliable. Isn't this a problem?
Update:
Thanks to Bert, I've tried it with ps aux > somefile
and the lines inside the file are cut exactly like how it was with grep and less!
Info: FreeBSD 10.2, bash 4.3.42, same when connecting over SSH or when logged in locally via KVM.
It's not the piping doing it. Part of your problem is your pager,
less
. By default it truncates at the same length as your terminal does. You can fix this by telling it not to do that:ps aux | less -S
ps
detects the window width and outputs to fitThe man page has one way to bypass this:
Another solution would be to pipe the output to a file
ps aux > somefile