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

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



In <[🔎] 20100306124710.GB25598@bobcox.com>, Bob Cox wrote:
>On Sat, Mar 06, 2010 at 06:21:27 -0600, Ron Johnson (ron.l.johnson@cox.net) 
wrote:
>> On 2010-03-06 04:28, Bob Cox wrote:
>>> ---------------------
>>> 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?
>>
>> How about:
>>
>>     read ...
>>     if [ -z "$FILEPATH" ]
>>     then
>>        FILRPATH=/usr/local/etc/"
>>     if
>
>Thanks Ron. I can see what you are getting at, but unless I am missing
>something, that still won't display the contents of the string to the
>user, providing him or her with the opportunity to accept or edit it.

PROMPT="stuff"
DEFAULT="path"

printf '%s [%s] ?' "$PROMPT" "$DEFAULT"
read FILEPATH
if [ -z "$FILEPATH" ]; then
	FILEPATH="$DEFAULT"
fi

-- 
Boyd Stephen Smith Jr.                   ,= ,-_-. =.
bss@iguanasuicide.net                   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy         `-'(. .)`-'
http://iguanasuicide.net/                    \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: