"read"命令可以在一行中最多容纳多少个字符 [英] what is the max number of characters 'read' command can take in one line

查看:64
本文介绍了"read"命令可以在一行中最多容纳多少个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下shell脚本可以从终端读取行

I have the following shell script to read lines from terminal

#!/bin/bash

while read line
do
if [ -z ${line} ]
then
    break
fi
echo ${line}
done

我不能输入超过256个字符.终端不允许我这样做(终端不打印超过256个字符的任何内容,甚至不换行.它只允许退格)

I cannot enter more than 256 characters. The terminal doesn't allow me to do so (Terminal doesn't print anything beyond 256 characters, not even new line. only thing it allows is backspace)

$ ./echo.sh
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

我正在使用solaris 10操作系统使用的终端是腻子bash版本3.2.52

Im using solaris 10 OS terminal used is putty bash version 3.2.52

这是对bash或腻子的限制吗?我知道将输入分成几行,但是我需要知道是否有办法克服输入作为读取命令的最大字符数

Is this a limitation in bash, or putty? I know to break my input into several lines, but I need to know if there is way to overcome maximum number of characters entered for read command as input

推荐答案

这是OS终端驱动程序中的限制.

This is limitation in the OS terminal drivers.

我们通常将其完全视为理所当然,但是当您输入 hi< Backspace> ello 并按Enter键时,该过程只会读取 hello .

We normally take it completely for granted, but when you enter hi<Backspace>ello and press enter, the process just reads hello.

终端驱动程序通过将行存储在内存中,然后在按下 Backspace 时删除该缓冲区中的最后一个字符来实现此目的.用于此的缓冲区具有一些人类规模的大小.在Linux上,它是4096字节,用于比较.

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.

您可以通过禁用行编辑来解决此问题:

You can get around this by disabling line editing:

stty -icanon

read 现在将一次读取更多数据,但是如果您按 Backspace ,则应用程序实际上将读取一个退格字符,而不是最后一行.

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.

这篇关于"read"命令可以在一行中最多容纳多少个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆