[wellylug] Default value in read

thomas thomas at adminporn.org
Wed May 9 10:39:44 NZST 2007


Hello Sigurd,

> $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" )


My first instinct was ${XX:=YY}, but read does not appear to directly 
support read-ing into such a construct.

..so you would want to go with somethinga bit more cumbersome like:

read -p "please provide domain name: " DEFAULTVALUE && 
DEFAULTVALUE=${DEFAULTVALUE:="google.com"}

this will fill the variable DEFAULTVALUE with google.com if no input is 
given, and with whatever input that is given if it is :-)

HTH,



thomas




More information about the wellylug mailing list