Increase command length for ksh shell on Redhat Linux

I have a ksh shell script and i need to pass arguments which are generated by data pulled from a database.

When the argument to the shell script is too long (about 4000 charecters) the below is the issue observed.

I copy the command which is 4000 charecters long from the logs and paste it for the ksh shell on my RedHat linux; then only part of the command (not the complete copied command text) gets pasted

Can you please help increase / tweak some settings so I can simply copy paste and execute the shell script irrespective of the command length or atleast increase it to a substantial length?

Below are the details:

# getconf LINE_MAX
2048
# getconf ARG_MAX
51200000
# getconf _POSIX_ARG_MAX 
51200000

Linux mymac 3.10.0-957.12.1.el7.x86_64 #1 SMP Wed Mar 20 11:34:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

However, I did not find any of the above variable in /usr/include/limits.h file.

I'm not sure what value I should change and in which file ?

Note: the issue of not being able to paste the entire command only happens with ksh shell. The problem is not seen with bash shell.

Can you please suggest ?

It's a hardcoded limit, not something trivially changed. Even if you coerce getconf into changing, it won't be reflected in programs. But I suspect you're using a crusty old pdksh/ksh88, newer ksh is quite willing to accept enormous arguments on Linux.

$ # create 5 kilobyte file
$ for ((X=0; X<5000; X++)) ; do printf "0" ; done > 5k
$ cat arg.ksh

#!/bin/ksh

echo "$1"

$ xargs ksh arg.ksh < 5k | wc -c

5001

$ ksh --version

  version         sh (AT&T Research) 93u+ 2012-02-29

$

xargs is cheating: it runs the ksh with max_args then again with the remaining args...
A correct test is

ksh arg.ksh $(cat 5k) | wc

Looks like i was not able to understand as well as explain the problem.

here is the problem where i'm running the test.sh script and passing a very long argument with terminal set to ksh like below.

command i wish to run:

./test.sh argone argtwo argthree ..... very lengthy string .... argtwohundredfour argtwohundredfive argtwohundredsix argtwohundredseven argtwohundredeight 

when i copy the above and paste it in my ksh terminal it does not paste the entire copied text but only till say "argtwohundredfour" as below.

./test.sh argone argtwo argthree ..... very lengthy string .... argtwohundredfour

I then have to copy the remaining args and add to the previous manually. entire thing does not get copied in one go in ksh like it does in bash.

That is the problem. If there is a solution to this I will be excited to know.

Maybe you hit the LINE_MAX=2048 ?
This should be the buffer for a physical line (usually an input line).
Try to construct a longer virtual line by inserting a \ at the very end of the physical line, and continue on the next physical line.
For example

./test.sh argone \
argtwo \
argthree \
...

Any other solution please ? As the arguments are constructed by variable substituted values constructed at runtime.

Considering I have root privileges , can I modify this setting somewhere ?

I've verified that it's not cheating in my case by having the script print an extra character. The count would be out several more if ksh were being run repeatedly.

To repeat: It's not a setting, it's hardcoded. Changing it won't change programs. You'd just make it lie.

It might be possible to build a custom ksh with a higher setting but that sounds far more difficult(installing compilers, headers, installing things in custom paths) than just getting the newer ksh which already does what you want. What version of ksh are you using? ksh --version

Moderator comments were removed during original forum migration.

@mohtashims

You never replied to this question :slight_smile:

Maybe you can follow up?

Thanks.