Over many years I used ksh. I like the possibility to use Esc v in command history to call the editor "vi". If this command in the history was spread over many lines - for example because of a while loop - "vi" shows this history also over many lines. With this feature it is easy possible to write complex statements without writing the input to a file.

Years ago I changes to bash. It has the same possibility with default shortcut Ctrl-X Ctrl-E. The slightly difference is that bash is merging all lines to one long line delimited with a semicolon. Syntax is still correct but we lose readability.

So what I am doing, I am calling ksh, if I see the commands become complex.

Is there a way to configure bash in a way not to merge the lines of the history and act as ksh is doing it?

Any help is welcome.



shopt -s lithist

If set, and the cmdhist option is enabled, multi-line commands are saved to the history with embedded newlines rather than using semicolon separators where possible.

I suspect the reason this isn't enabled by default is because people often use commands like history | grep something to find history entry numbers. If a history entry is split across multiple lines, the line that matches grep won't always contain the entry number.

|improve this answer|||||
  • Barner, many thanks. This makes the life much easier. I can get over not to see the complete statement if grepping in the history. Mirabolis, thanks for making a nice posting. But if you do it don't change the content in a way that the context is lost. – hans Feb 5 '17 at 21:49
  • If you want Mirabolis to be notified of your comment, put @ before his name. The comment about the edit should be below the main question, it's not related to my answer. It looks like all his edits were just formatting, not content, so no context was lost. – Barmar Feb 6 '17 at 2:10
  • Hi Barmar - thanks for coming back. I wrote originally ctrl-x ctrl-e. Most people will understand this as pressing the ctrl key together with x and then ctrl together with e. Now you can read ctrl-x+ctrl+e. What's that. That's not my posting. I do not understand why people have the constraint to modify others postings. - hans – hans Feb 6 '17 at 19:43
  • @hans Users with < 2000 reputation are allowed to edit questions and answers, but their edits must be reviewed and approved before they're applied. Users with 2000+ reputation can edit without requiring review. You will always be notified if someone edits your posts, so if you think they made a mistake you can correct it. This one seems like a very minor one, most will understand it with the extra -, but why haven't you fixed it? – Barmar Feb 6 '17 at 19:52
  • many thanks for your explanation. You are a great help. In the meantime I fixed the modified posting. – hans Feb 12 '17 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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