Startup a fresh GTK emacs with no config with emacs -Q. Then run M-x shell. Then at the prompt:

$ ps -ef

Long commands will be truncated to the frame width, like this:

root      526315       2  0 15:08 ?        00:00:00 [kworker/6:2-eve

So far, this matches normal terminal behavior. But if you do:

$ ps -ef | grep kworker

In emacs shell-mode it will still be truncated, but in a non-emacs terminal (e.g. xterm) the line will not be truncated. Why is this? How do I get it to match normal terminal behavior?

I've noticed shell-mode will respect $COLUMNS, so you can set it to a large value as a temporary fix, but this is unnecessary in a regular terminal where piping will prevent truncation regardless of the $COLUMNS value, and shell-mode always assigns $COLUMNS back to the frame width on the next command.

1 Answer 1


In bash, export -p | grep COLUMNS shows me that this variable is exported in my *shell* buffer, but not in my regular terminal.

export -n COLUMNS in my *shell* buffer therefore has the effect you're after.

Original answer follows...

The man page for my version of ps says:

If ps can not determine display width, as when output is redirected (piped) into a file or another command, the output width is undefined (it may be 80, unlimited, determined by the TERM variable, and so on). The COLUMNS environment variable or --cols option may be used to exactly determine the width in this case. The w or -w option may be also be used to adjust width.

Where the latter options are:

  • w Wide output. Use this option twice for unlimited width.
  • -w Wide output. Use this option twice for unlimited width.

And indeed for me, ps -wwef | grep <whatever> has the desired effect in a shell buffer.

My ps also support any of the following set a specific screen width:

  • --cols <N>
  • --columns <N>
  • --width <N>
  • this is a good workaround, but doesn't explain why the emacs behavior is different. when I invoke ps ... | grep .. bash is still responsible for doing the piping between ps and grep, so I wouldn't expect ps to behave differently Commented Apr 18 at 21:25
  • They'll be making decisions based on the environment they observe, and something in those differences will be driving that decision. I don't know what, specifically. As the chosen width is explicitly "undefined" in that situation, though, neither of the two outcome is incorrect.
    – phils
    Commented Apr 18 at 22:27
  • In my case at least, I suspect the decision is driven by the fact that in the two different scenarios I get a different result from the following: echo $COLUMNS | sh -c 'cat - && echo and && echo $COLUMNS'
    – phils
    Commented Apr 19 at 1:25
  • export -n COLUMNS in my *shell* buffer has the effect you're after. export -p | grep COLUMNS shows that it is exported in my *shell* buffer, but not in my regular terminal.
    – phils
    Commented Apr 19 at 1:35
  • I observe that if you change COLUMNS in the shell buffer, then hit enter a couple of times, the old value magically comes back Commented Apr 19 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.