简体   繁体   中英

KornShell (ksh) wraparound

Okay, I am sure this is simple but it is driving me nuts. I recently went to work on a program where I have had to step back in time a bit and use Redhat 9. When I'm typing on the command line from a standard xterm running KornShell (ksh), and I reach the end of the line the screen slides to the right (cutting off the left side of my command) instead of wrapping the text around to a new line. This makes things difficult for me because I can't easily copy and paste from the previous command straight from the command line. I have to look at the history and paste the command from there. In case you are wondering, I do a lot of command-line awk scripts that cause the line to get quite long.

Is there a way to force the command line to wrap instead of shifting visibility to the right side of the command I am typing?

I have poured through man page options with no luck.

I'm running:

  • XFree86 4.2.99.903(174)
  • KSH 5.2.14.

Thanks.

Did you do man ksh ?

You want to do a set -o multiline .

Excerpt from man ksh :

multiline:

The built-in editors will use multiple lines on the screen for lines that are longer than the width of the screen. This may not work for all terminals.

eval $(调整大小)应该这样做。

If possible, try to break the command down to multiple lines by adding \\ ie:

$ mycommand -a foo \
  -f bar \
  -c dif

The simple answer is:

$ set -o multiline

ksh earlier than 5.12, like the ksh shipped with NetBSD 6.1, doesn't have this option. You will have to turn off current Interactive Input Line Editing mode, which is usually emacs:

$ set +o emacs

This turns off a lot of featuers altogether, like tab-completion or the use of 'Up-arrow' key to roll back the previous command.

If you decide to get used to emacs mode somehow, remember ^a goes to the begining of the line ("Home" key won't workk) and ^e goes to the end.

I don't know of a way of forcing the shell to wrap, but I would ask why you'd be writing lines that long. With awk scripts, I simply wrap the script in single quotes, and then break the lines where I want. It only gets tricky if you need single quotes in the script -- and diabolical if you need both single and double quotes. Actually, the rule is simple enough: use single quotes to wrap the whole script, and when you want a single quote in the script, write '\\'' . The first quote terminates the previous single-quoted string; the backslash-single quote yields a single quote; and the last single quote starts a new single quoted string. It really gets hairy if you need to escape those characters for an eval or something similar.

The other question is - why not launch into an editor. Since I'm a die-hard vim nutcase (ok - I've been using vi for over 20 years, so it is easier for me than the alternatives), I have Korn shell set to vi mode (set -o vi), and can do escape-v to launch the editor on whatever I've typed.

This is kind of a pragmatic answer, but when that's an issue for me I usually do something like:

strings ~/.history | grep COMMAND

or

strings ~/.history | tail

(The history file has a little bit of binary data in it, hence 'strings')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM