4

On Solaris 11 running Bash 4.4.19 (the standard install?) there appears to be a 256 character limit of sorts on the input line. I'd like to understand where this limit is coming from.

I've skimmed the man page, but I don't find anything which addresses this. This happens only when the readline library is not in use. In the lines below, the length of echo 678[...]23456 is 256 characters

sfmg10 0 5:37pm> uname -a
SunOS sfmg10 5.11 11.4.6.4.0 sun4v sparc sun4v
sfmg10 0 5:37pm> /usr/bin/bash --version
GNU bash, version 4.4.19(1)-release (sparc-sun-solaris2.11)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
sfmg10 0 5:38pm> /usr/bin/bash -norc -noprofile
bash-4.4$ set -o emacs
bash-4.4$ echo 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
bash-4.4$ set +o emacs
bash-4.4$ echo 67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
bash-4.4$ echo 678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
bash-4.4$ echo 6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678
bash: 8: command not found

The first line with an echo is 258 characters and executes as expected.
The second echo line is 256 characters executes as expected.
The third echo line is 257 characters and produces no output.
The fourth echo line is 258 characters and bash appears to throw out the first 257 characters and then execute the remaining characters.

I've tried this on several Linux, Mac OSX, and FreeBSD systems and could not reproduce the odd behavior.

On Solaris 9 with bash 2.05.0(1)-release and Solaris 10 with bash 3.2.57(1)-release (the same version as one of the Mac OSX boxes I get the same odd behavior as Solaris 11. I had thought that Solaris 10 was slightly different, but that was because I was accessing it through putty instead of an xterm. The putty/xterm difference is described in my comment below.

Why does bash throw out the first 257 characters of lines 257 characters or longer? Is this a bug or a feature? Is this caused by bash, Solaris, or something else? Can I change this number without re-compiling bash?

Mark Geary
  • 41
  • 4
  • 4
    I think the limit is on the terminal implementation, or the `readline` implementation limit. To verify this, try to test these in a script rather than with the interactive terminal. – Léa Gris Sep 25 '19 at 14:39
  • I put the commands in a script and there is no line limit (or it is greater than 100k characters). But it is primarily the interactive case I am interested in. I don't think `readline` has anything to do with the limit, since the limit disappears when readline processing is turned on. – Mark Geary Sep 25 '19 at 14:59
  • How are you accessing the command line? GUI window? Remote SSH? Console? – Andrew Henle Sep 25 '19 at 15:36
  • 1
    I'm running an xterm on the Solaris 11 box and displaying on a CygwinX server. If I open a putty window and connect to the Solaris box with ssh, the length limits are the same, but the reaction to hitting the limit is different. In a putty window, the shell stops accepting input after 257 characters until I hit `^C`. If I open an xterm on a Linux box and telnet to the Solaris 11 box, the length limits are still the same but the reaction to hitting the limit is like it is in the putty window. – Mark Geary Sep 25 '19 at 16:06
  • Do the commands "stty imaxbel" / "stty -imaxbel" make any difference to the behaviour? – psmears Sep 26 '19 at 15:17
  • There seems to be much confusion on just which limit would apply (it has been that way for a while). There is good discussion to help understand which limit it may be at [What defines the maximum size for a command single argument?](https://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument) and another foray into it at [Bash command line and input limit](https://stackoverflow.com/questions/19354870/bash-command-line-and-input-limit) – David C. Rankin Sep 26 '19 at 15:21
  • @DavidC.Rankin, those links are about ARG_MAX, I believe the OP is interested in the TTY-specific limits discussed in [How to read over 4k input without new lines on a terminal](https://unix.stackexchange.com/questions/131105/how-to-read-over-4k-input-without-new-lines-on-a-terminal/131274#131274), for which the relevant constant is `N_TTY_BUF_SIZE`. – Charles Duffy Sep 26 '19 at 17:17
  • @MarkGeary, ...btw, insofar as we already *have* [an answered instance of this question](https://unix.stackexchange.com/questions/131105) over at [unix.se], and it's about interactive shell usage rather than writing new software, I do suspect that migrating it there may be more appropriate (as SO's scope is strictly limited software development as such). – Charles Duffy Sep 26 '19 at 17:19
  • Ah, just noticed that I have to click "Show 3 more comments". – Mark Geary Sep 27 '19 at 20:23
  • "stty imaxbel" / "stty -imaxbel" appears to be the difference I am seeing between using xterm and using putty/telnet. putty apparently starts with `stty imaxbel` while xterm starts with `stty -imaxbel`. Same limit in either case, just a different way of showing me that the limit has been reached. I can switch the behaviors by toggling imaxbel. The stty man page refers to "input stream overflows", which gives me something new to look into. Though whose buffer is overflowing puzzles me. 256 seems awfully small for an input buffer. – Mark Geary Sep 27 '19 at 21:10
  • @CharlesDuffy, perhaps my question should be moved--I didn't notice the Unix & Linux site when I was scanning the list of the 175 sites--but as far as I can tell, I can't move my question on my own. – Mark Geary Sep 27 '19 at 23:40
  • The question that you mention looks interesting. It will take me some time to digest it all. – Mark Geary Sep 28 '19 at 00:19

0 Answers0