Finding the Maximum Number of Command Line Characters

Whilst idling in EFNet #php.doc, Kalle brought up the question about maximum input length from the command line on Linux. It’s acceptable to presume that the maximum length is ~65536, as you might expect ((32 * 8)2). But how can one be sure?

A bit of code:


#!/bin/bash
i=0;
str="PHP";
len=0;
while(test "X`echo $str`" = "X$str") > /dev/null 2>1 && res=`expr "X$str" : ".*" 2>&1` && len=$res; do
i=`expr $i + 1`;
str=$str"X"$str;
done;
echo "Maximum characters allowed via command line: $len";

That’ll do, pig. That’ll do.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

The CAPTCHA cannot be displayed. This may be a configuration or server problem. You may not be able to continue. Please visit our status page for more information or to contact us.

This site uses Akismet to reduce spam. Learn how your comment data is processed.