Re: bash, read, and tab completion
On 11/9/05, Matt Price <matt.price@utoronto.ca> wrote:
> I want to make sure that I save my .config in a safe location.
> In bash I supose this is easy:
>
> echo -n "Save this config as: "
> read filename
> cp .config $filename
>
> however, there's no guarantee there that I've inputted a valid path.
> Is there a way to do the following while 'read'ing:
>
> - provide a default value (e.g. /usr/src/configs/latest-config)
> - provide bash-style tab completion (so that I can be sure I'm saving
> in a valid directory)
"read -e filename" will use the readline library, which understands
tab completion. I don't know if it's possible to set a default value.
You could always go through some gymnastics:
filename=/usr/src/configs/latest-config
read -e -p "Save this config as: [$filename] " tmpfname
[ "x$tmpfile" = "x" ] || filename=$tmpfile
The last line could probably also be
[ -z $tmpfile ] || filename=$tmpfile
--
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com
Reply to: