Skip to main content

Read Command

Read allows you to prompt the user for information, and store the user's response temporarily in a variable. You can use Write to display the contents of the variable. In this tutorial, the user's responses to Read are CAPITALIZED.


USER>read x
USER>write "You just typed: ", x
You just typed: BEST FRIEND

Since it allows prompting, Read shares some functionality with Write. You can wait for a user to respond indefinitely, or you can specify a timeout: how long (in seconds) to wait. If the user presses Enter without entering any characters, the variable will contain the zero-length (empty) string.

You can wait for any number of characters, or you can specify a maximum length. In this case, the user may enter fewer characters than you specify, pressing Enter when finished. Or, if the user enters the maximum number of characters, Read terminates automatically.


USER>read ?30, "Enter your name: ", n
                              Enter your name: ALEXANDER
USER>read !, "You have 5 seconds to respond: ", x:5

You have 5 seconds to respond: I TYPED THIS IN 5 SECONDS
USER>read !, "Type 5 characters and don't press Enter: ", z#5

Type 5 characters and don't press Enter: ABCDE
FeedbackOpens in a new tab