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

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



On 2010-03-06 06:47, 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:
What I am trying to do is "preload" a bash read command with a value
which can be accepted, edited or changed by the user.  Some googling
shows that this is dead easy to with the -i option which appeared in
bash version 4 - I have found this:

---------------------
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.


A tiny C/Python/Perl program?  Make those lousy SOBs upgrade to BASH4?

--
Ron Johnson, Jr.
Jefferson LA  USA

"If God had wanted man to play soccer, he wouldn't have given
us arms."  Mike Ditka


Reply to: