Interactive versus non-interactive scripts

The script we have created so far uses user input, but it can't really be called interactive. As soon as the script is fired off, with or without arguments to the parameters, the script runs and completes.

But what if we do not want to use a long list of arguments, instead prompting the user for the information that is needed?

Enter the read command. The basic usage of read looks at input from the command line, and stores it in the REPLY variable. Try it out yourself:

reader@ubuntu:~$ readThis is a random sentence!reader@ubuntu:~$ echo $REPLYThis is a random sentence!reader@ubuntu:~$

After you start the read command, your terminal will go down a line and allow you to type anything you want. As soon ...

Get Learn Linux Shell Scripting - Fundamentals of Bash 4.4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.