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

2011-10-09 Thread au2by2

Won't this do what you want?  It obviously works on old bash.

  echo -n prompt:; writevt -t `tty` -T default; read a;

For example:

testuser@bartlett:~$ echo -n prompt:; writevt -t `tty` -T default;\ 
 read a; declare -p a BASH_VERSION

prompt:default
declare -- a=default
declare -- BASH_VERSION=3.1.17(1)-release
testuser@bartlett:~$
testuser@bartlett:~$
testuser@bartlett:~$ echo -n prompt:; writevt -t `tty` -T default;\ 
 read a; declare -p a BASH_VERSION

prompt:something else
declare -- a=something else
declare -- BASH_VERSION=3.1.17(1)-release
testuser@bartlett:~$

Sorry to take so long to respond; we've had a large team working on this 
question full-time to develop this solution. :-)



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4e925184.7010...@internode.on.net



Re: Bash read command: want to preload some data

2011-10-09 Thread au2by2
Apologies, line wrapping messed up my previous reply, corrected here (I 
hope).


Won't this do what you want?  It obviously works on old bash.

  echo -n prompt:; writevt -t `tty` -T default; read a;

For example:

testuser@bartlett:~$ echo -n prompt:; writevt -t `tty` -T default; 
read a; declare -p a BASH_VERSION


prompt:default
declare -- a=default
declare -- BASH_VERSION=3.1.17(1)-release
testuser@bartlett:~$
testuser@bartlett:~$

testuser@bartlett:~$ echo -n prompt:; writevt -t `tty` -T default; 
read a; declare -p a BASH_VERSION


prompt:something else
declare -- a=something else
declare -- BASH_VERSION=3.1.17(1)-release
testuser@bartlett:~$

Sorry to take so long to respond; we've had a large team working on this 
question full-time to develop this solution. :-)



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4e92707b.1020...@internode.on.net



Re: Bash read command: want to preload some data

2010-03-08 Thread Bob Cox
On Sun, Mar 07, 2010 at 21:11:29 -0500, A. Costa (agco...@gis.net) wrote: 

 Bash isn't strictly needed, plain Bourne shell works, using parameter 
 substitution

[...]

Thank you for you time and trouble.  As it happens, I did in fact
upgrade this lenny box to use bash version 4.1-1 and all is now working
perfectly with the -i option - but thanks again for your efforts.

 (Debian's minimal 'dash' also has a 'read -i', so for
 current Debian, the '-i' is universal.  Earlier versions,
 or other *nixs might not though.)

Not so sure that is correct about dash:

$ apt-cache policy dash
dash:
  Installed: 0.5.5.1-3
  Candidate: 0.5.5.1-3

$ ps -p $$
  PID TTY  TIME CMD
11777 pts/500:00:00 dash

$ read -e -p Enter something: -i Default data data
read: 16: Illegal option -e

$ read -p Enter something: -i Default data data
read: 17: Illegal option -i

$ read -p Enter something: data
Enter something:  

So it seems it understands neither the -e nor -i options (not that it
really matters and TBH it is hardly surprising as dash is supposed to be
very lightweight).

-- 
Bob Cox.  Stoke Gifford, near Bristol, UK.
Please reply to the list only.  Do NOT send copies directly to me.
http://bobcox.com/


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100308172721.ga4...@bobcox.com



Re: Bash read command: want to preload some data

2010-03-08 Thread A. Costa
On Mon, 8 Mar 2010 17:27:22 +, Bob Cox wrote:
  (Debian's minimal 'dash' also has a 'read -i', so for
  current Debian, the '-i' is universal.  Earlier versions,
  or other *nixs might not though.)

 Not so sure that is correct about dash...

Whoops, you're right, it seems I did a 'man sh' and leapt to
conclusions.  Turns out 'man sh' unexpectedly links to 'man bash'.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100308195329.06272a92.agco...@gis.net



Re: Bash read command: want to preload some data

2010-03-07 Thread A. Costa
Bash isn't strictly needed, plain Bourne shell works, using parameter 
substitution

   man sh | grep -A 2 -i parameter:-
   ${parameter:-word}
 Use  Default  Values.   If parameter is unset or null, the expansion of
 word is substituted.  Otherwise, the value of parameter is substituted.

So:

p=/foobar
read -p gimme a dir or accept default ($p):  x
x=${x:-$p}
echo $x

...if the user hits Enter it shows:

gimme a dir or accept default (/foobar): 
/foobar

It's better to put that in a function:

input_dir() { p=${1:-/foobar} ; read -p gimme a dir or accept 
default ($p):  x ; x=${x:-$p} ; echo $x ; }

This function can even take a parameter, if the default
dir needs to be changed on the fly:

% input_dir 
gimme a dir or accept default (/foobar): /foobar2
/foobar2

# store results of routine in $x
% x=`input_dir /tmp`
gimme a dir or accept default (/tmp): 
% echo $x
/tmp

(Debian's minimal 'dash' also has a 'read -i', so for
current Debian, the '-i' is universal.  Earlier versions,
or other *nixs might not though.)

HTH...


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100307211129.593535b4.agco...@gis.net



Bash read command: want to preload some data

2010-03-06 Thread Bob Cox
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?

-- 
Bob Cox.  Stoke Gifford, near Bristol, UK.
Please reply to the list only.  Do NOT send copies directly to me.
http://bobcox.com/


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100306102840.ga25...@bobcox.com



Re: Bash read command: want to preload some data

2010-03-06 Thread Ron Johnson

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

--
Ron Johnson, Jr.
Jefferson LA  USA

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


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4b9248c7.5070...@cox.net



Re: Bash read command: want to preload some data

2010-03-06 Thread Bob Cox
On Sat, Mar 06, 2010 at 06:21:27 -0600, Ron Johnson (ron.l.john...@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.

-- 
Bob Cox.  Stoke Gifford, near Bristol, UK.
Please reply to the list only.  Do NOT send copies directly to me.
http://bobcox.com/


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100306124710.gb25...@bobcox.com



Re: Bash read command: want to preload some data

2010-03-06 Thread Ron Johnson

On 2010-03-06 06:47, Bob Cox wrote:
On Sat, Mar 06, 2010 at 06:21:27 -0600, Ron Johnson (ron.l.john...@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


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org

Archive: http://lists.debian.org/4b925a94.6020...@cox.net



Re: Bash read command: want to preload some data

2010-03-06 Thread André Berger
* 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


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100306143109.ga54...@fuchs



Re: Bash read command: want to preload some data

2010-03-06 Thread Boyd Stephen Smith Jr.
In 20100306124710.gb25...@bobcox.com, Bob Cox wrote:
On Sat, Mar 06, 2010 at 06:21:27 -0600, Ron Johnson (ron.l.john...@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.   ,= ,-_-. =.
b...@iguanasuicide.net   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/\_/


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


Re: Bash read command: want to preload some data

2010-03-06 Thread Bob Cox
On Sat, Mar 06, 2010 at 09:44:13 -0600, Boyd Stephen Smith Jr. 
(b...@iguanasuicide.net) wrote: 

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

Boyd and André - thank you both for your suggestions, which are probably
as good as it well get, without the -i functionality in bash4 (assuming
I stick to bash - Ron's hint re python noted).  To be of use to me, I
really want the ability to edit the existing text when it is offered to
the user and I think an upgrade to bash 4 is going to be worth a try as
this is just a part of a quite big bash script which I have been
constantly tweaking for years.

Thanks again.

-- 
Bob Cox.  Stoke Gifford, near Bristol, UK.
Please reply to the list only.  Do NOT send copies directly to me.
http://bobcox.com/


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100306163526.ge25...@bobcox.com