Automating interactive input
We looked at commands that accept arguments on the command line. Linux also supports many interactive applications ranging from passwd
to ssh
.
We can create our own interactive shell scripts. It's easier for casual users to interact with a set of prompts rather than remember command line flags and the proper order. For instance, a script to back up a user's work, but not to back up and lock files, might look like this:
$ backupWork.sh
- What folder should be backed up?
notes
- What type of files should be backed up?
.docx
Automating interactive applications can save you time when you need to rerun the same application and frustration while you're developing one.
Getting ready
The first step to automating a task is to run it and note what you do. The script command discussed earlier may be of use.
How to do it...
Examine the sequence of interactive inputs. From the previous code, we can formulate the steps of the sequence like this:
notes[Return]docx[Return]
In addition to...