简体   繁体   English

KornShell(ksh)环绕

[英]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. 我最近去了一个程序,我不得不退后一点并使用Redhat 9.当我在运行KornShell(ksh)的标准xterm的命令行上输入时,我到达了结束时屏幕右侧滑动(切断命令的左侧),而不是将文本环绕到新行。 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. 如果你想知道,我做了很多命令行awk脚本,导致行很长。

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) XFree86 4.2.99.903(174)
  • KSH 5.2.14. KSH 5.2.14。

Thanks. 谢谢。

Did you do man ksh ? 你做man ksh吗?

You want to do a set -o multiline . 你想做一set -o multiline

Excerpt from man ksh : 摘自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: 如果可能,尝试通过添加\\ 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. 早于5.12的ksh,就像NetBSD 6.1附带的ksh一样,没有这个选项。 You will have to turn off current Interactive Input Line Editing mode, which is usually emacs: 您必须关闭当前的交互式输入行编辑模式,通常是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. 如果您决定以某种方式习惯emacs模式,请记住^ a进入行的开头(“Home”键不会工作)并且^ e将结束。

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. 我不知道强迫shell换行的方法,但我会问为什么你要写那么长的行。 With awk scripts, I simply wrap the script in single quotes, and then break the lines where I want. 使用awk脚本,我只需将脚本包装在单引号中,然后打破我想要的行。 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. 如果您需要为eval或类似的东西逃脱这些角色,它真的会变得毛茸茸。

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. 因为我是一个顽固的vim nutcase(好吧 - 我已经使用vi超过20年,所以它比我更容易替代),我将Korn shell设置为vi模式(set -o vi),并且可以执行escape-v来启动编辑器,无论我输入什么。

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') (历史文件中包含一点二进制数据,因此'字符串')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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