Currently I am using printf
and read
or read -p
to prompt the user and gather his input.
However, for some of my scripts it would be very useful to supply editable default answers, like:
Please specify the correct path to your file:
/some/long/ugly/default/path/to/user.file # <-- this line should be
# editable and read
# back in after the
# user hits [ENTER]
At the moment my script prints /some/long/...
and asks if this is already correct by prompting correct? [y/n]
.
If the user hits n
the user gets prompted for a custom path. However, in this scenario the user has to enter the full path by hand. Since mostly only the last directory or file changes, I would like to supply a "default answer" that is editable by the user. Thus, the user just has to change the filename, for example, and hit [ENTER].
Reading man read
looks like read
can not do this?
Is this task rather complicated? Or are there tools available similar to read
that allow such behavior?