[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash "read" command: want to preload some data



* Bob Cox (2010-03-06):
[...]
> ---------------------
> Example: ask for a path with a default value.
> Note: The -i option was introduced with Bash 4.
> read -e -p "Enter the path to the file: " -i "/usr/local/etc/" FILEPATH
> The user will be prompted, he can just accept the default, or edit it.
> ---------------------
> 
> This is exactly what I want.  However, for the sake of compatibility, I
> would like to do the same thing using older versions of bash, even if it
> means messier coding.  Does anyone have any ideas on how to do this
> please?

  PRELOADED="/usr/local/etc"
  read -e -p "Enter the filepath (Use . for the current directory, just hit ENTER to accept the default ${PRELOADED}, or type something else): " FILEPATH
  test -z ${FILEPATH} && FILEPATH=${PRELOADED}
  echo "Will use value: ${FILEPATH}"

-André

-- 
May as well be hung for a sheep as a lamb!
Linkstation/KuroBox/HG/HS/Tera Kernel 2.6/PPC from <http://hvkls.dyndns.org>
iPhone <http://hvkls.dyndns.org/downloads/documentation/README-iphone.html>


Reply to: