1

Trying to read a long input into a variable from ZSH on MacOS.

    echo "URL: "
    read URL

input is always truncated to 1024 chars... if I try and type additional chars nothing happens.

  • Input is copy/pasted from PostMan, its an S3 signed upload URL

  • If I try and delete a few chars from the end (after pasting) I am only able to manually type as many chars as I deleted

  • I tried using the -n option to no avail (nothing gets read into the variable)

How can I read a long input? ~1500 chars

SoonGuy
  • 131

1 Answers1

0

read itself just reads bytes from the terminal, it has no control over how the terminal reads those bytes. And the terminal has a limited line length which, as far as I recall, can't be changed easily (or at all?). The terminal's line editor is also very crude, just supporting backspace and not other editing commands.

Use vared instead. This is somewhat similar to read (but with different options), but it's specialized to reading from a terminal and it uses zsh's line editor. That makes it a lot more user-friendly, in addition to not having a line length limit.

URL=
vared -p "URL: " URL

vared always reads from the terminal, not from standard input. If you want to support reading input redirected from a file or pipe, check whether standard input is a terminal with the -t condition..

URL=
if [[ -t 0 ]]; then
  vared -p "URL: " URL
else
  read -r URL
fi