Sometime back, was working with a colleague and came across a new requirement. We needed a script that takes a path as input. (It is an interactive shell script) The catch is, we wanted to provide some flexibility for the user and so we wanted the path to be auto-completed. (tab fills up the path)

When we tried “read -e path” and “echo $path“.. it didn’t help 😦 So, we did a “man read” and found that read can store the input in REPLY variable and you can use it.

read -e
echo $REPLY

This worked.. When we used tabs, it auto-filled and we can use REPLY variable to get the input.  This was tried on an SLES machine. When I tried “read -e path” on ubuntu, auto-completion itself worked. So, looks like the auto-completion is different between SLES and Ubuntu..

Moral of the story: (Apart from Ubuntu is convenient), read stores the input in REPLY variable and that can be used in your scripts 🙂

Advertisements