2

I have a file on disk which contains some text I want to display on the screen. You can do it like this:

dialog --yesno "`cat FILE`" 10 100

However, I'm concerned that if FILE becomes large, I'm likely to exceed the command length limits of the shell. Is there some other way to accomplish this task?

I want to display the contents of the file so the user can scroll through it (if it's really long), and then select what to do next. (I've relabelled the "yes" and "no" buttons to something more meaningful.) Presumably trying to pipe six pages of text through the command line like this is going to break.

  • What exactly is the task you are trying to accomplish? Are you trying to ensure the file does not exceed the capacity of dialog to display? Or are you seeking an alternative to dialog which will display an arbitrarily long amount of text? Would --textbox file height width work or do you need the user to agree to a large amount of text? Or what? –  Apr 15 '14 at 16:27
  • The command length is pretty damn long, will this ever be a problem? – terdon Apr 15 '14 at 16:27
  • I was under the impression that the command line is limited to 255 characters. The text could end up being larger than that. – MathematicalOrchid Apr 15 '14 at 16:34
  • According to man: --max-input size Limit input strings to the given size. If not specified, the limit is 2048.. I don't know if there is a limit for Bash. I've certainly never hit it. –  Apr 15 '14 at 16:40
  • OK, so that's significantly higher that I had expected. It still feels somehow "wrong" to be sending this much data via command arguments, rather than through a pipe or a file or something... Is there maybe some way to use the --file option? – MathematicalOrchid Apr 15 '14 at 16:46
  • @awk_FTW there is no limit for bash - the limit is imposed by the kernel, see http://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument. If the command is a bash built-in there is no limit. – Graeme Apr 15 '14 at 16:46
  • 2
    --textbox takes a file as an argument. Have you tried putting the arguments in a file? `The "--file" option tells dialog to read parameters from the file named as its value.

    dialog --file parameterfile`

    –  Apr 15 '14 at 16:50

1 Answers1

3

Looking at the man page for this there does seem to be any way to avoid passing the text as an argument - there appears to be no way to pipe the data in or have dialog read directly from the file. However, you could limit the size of the argument using head. On most Linux systems the maximum size for a single argument is 32KiB, so you could do:

dialog --max-input 32768 --yesno "$(head -c 32K FILE)" 10 100

The maximum size for a single argument is defined by MAX_ARG_STRLEN which you will find in /usr/include/linux/binfmts.h if you have kernel headers installed. Usually the value is PAGE_SIZE * 32 where PAGE_SIZE is usually 1KiB (see /usr/include/linux/a.out.h).

Of course these values can be completely reconfigured. Moreover MAX_ARG_STRLEN is Linux specific and was introduced in Linux 2.6.23. For more information about what the limits actually are, please see What defines the maximum size for a command single argument?.

Update

Oops, you can actually use the --file argument for this. It looks like you can do something like (without having tested):

{
  echo -n \"
  sed 's/"/\"/' FILE
  echo -n \"
} | dialog --yesno --file '&1' 10 100

No need for the sed if you know there are no quotes in the file. Or alternatively just put everything you need in the file (quotes, --yesno and all) and simply do:

dialog --file FILE
Graeme
  • 34,027