[wellylug] Default value in read
Daniel Pittman
daniel at rimspace.net
Wed May 9 14:50:54 NZST 2007
Sigurd Magnusson <sigurd at silverstripe.com> writes:
> Its fine to do this...
>
> read -p "Please provide domain name, without www prefix, e.g.
> google.com: " domainname ;
>
> But how do I do this?
>
> $defaultvalue=google.com
> read -p "Please provide domain name, without www prefix, e.g.
> google.com: " $defaultvalue domainname ;
>
> (In which I want the user to be able to be able to EDIT the default
> value, as most times the default is correct, or needing a minor change,
> e.g. ".com" might change to "co.nz" )
Portable, in the shell only? You can't. The canonical version of this
in portable shell is:
default='google.com'
echo -n "Enter the domain: [$default] "
read myvar
if [ x"$myvar" = x"" ]; then myvar="$default"; fi
If you want to do something non-portable you could look and see which,
if any, shell offers readline support, but I don't think it is worth it.
Regards,
Daniel
--
Digital Infrastructure Solutions -- making IT simple, stable and secure
Phone: 0401 155 707 email: contact at digital-infrastructure.com.au
http://digital-infrastructure.com.au/
More information about the wellylug
mailing list