我有以下 shell 脚本来从终端读取行
#!/bin/bash
while read line
do
if [ -z ${line} ]
then
break
fi
echo ${line}
done
我无法输入超过 256 个字符。终端不允许我这样做(终端不会打印超过 256 个字符的任何内容,甚至不打印新行。它唯一允许的是退格键)
$ ./echo.sh
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
我在用着
Solaris 10 操作系统
使用的终端是putty
bash 版本 3.2.52
这是 bash 或 putty 的限制吗?我知道将输入分成几行,但我需要知道是否有办法克服为读取命令输入的最大字符数
这是操作系统终端驱动程序的限制。
我们通常认为这是理所当然的,但是当你进入hi<Backspace>ello
然后按回车键,该过程只是读取hello
.
The terminal driver makes this happen by storing the line in memory, and then deleting the last character in that buffer when you press Backspace.
The buffer used for this has some human scale size. On Linux it's 4096 bytes, for comparison.
您可以通过禁用行编辑来解决此问题:
stty -icanon
read
will now read more data at a time, but if you press Backspace, the application will actually read a backspace character instead of the final line.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)