O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading "n" characters without pressing Return

read is an important Bash command that can be used to read text from keyboard or standard input. We can use read to interactively read an input from the user, but read is capable of much more. Let's look at a new recipe to illustrate some of the most important options available with the read command.

Getting ready

Most of the input libraries in any programming language read the input from the keyboard; but string input termination is done when Return is pressed. There are certain critical situations when Return cannot be pressed, but the termination is done based on number of characters or a single character. For example, in a game a ball is moved up when up + is pressed. Pressing + and then pressing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required