Supplying Script Input on the Command Line

So far, you have created scripts that either don’t need any input from the user at all, or that have to interact directly with the user every time you run them. You will often find it convenient to give a script all the information it needs when you invoke it on the command line so that it won’t have to ask you any questions while it runs. This is especially true if you’re going to run the script in the background, because you don’t have the chance to give any extra input to such a script—running it in the background disconnects it from the terminal. This is also useful when another script is going to be running your script and passing it information.

In general, using echo to prompt and read to get ...

Get Practical UNIX 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.