Re: wrong PS1 var width calculation

2008-12-09 Thread Roman Rakus

Cheng Renquan wrote:

On Tue, Dec 9, 2008 at 11:40 AM, Chet Ramey <[EMAIL PROTECTED]> wrote:
  

Investigate patch 44.  It should fix this.



From where?
  

From
ftp://ftp.gnu.org/gnu/bash/bash-3.2-patches/

Or please tell a bash repository version, I'll test it.

  

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




  


RR




Re: passing array to command line argument.

2008-12-09 Thread Chet Ramey
> 
> Hello i would like to pass an array to my script command line argument, but
> only the first element of the array is displayed.  Here is my process :
> 
> script1:
> my_array=(el1 el2 el3)
> script2 -f $my_array

You're only passing the first element of the array to script2.  An
unsubscripted word expansion expands to the first element of an array.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://tiswww.tis.case.edu/~chet/




passing array to command line argument.

2008-12-09 Thread Dolphin06

Hello i would like to pass an array to my script command line argument, but
only the first element of the array is displayed.  Here is my process :

script1:
my_array=(el1 el2 el3)
script2 -f $my_array

script2:
while getopts ":f:" opt ; do
 case $opt in
  f ) arr="$OPTARG" ;;
 esac
done

echo "arr : [EMAIL PROTECTED]"
-- 
View this message in context: 
http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20914576.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: passing array to command line argument.

2008-12-09 Thread Dolphin06

Hello,
So how can i pass the entire array, i m new to shell scripting so i do not
really understand when you talk about unsubscripted word expansion
Thank you for helping.


Chet Ramey wrote:
> 
>> 
>> Hello i would like to pass an array to my script command line argument,
>> but
>> only the first element of the array is displayed.  Here is my process :
>> 
>> script1:
>> my_array=(el1 el2 el3)
>> script2 -f $my_array
> 
> You're only passing the first element of the array to script2.  An
> unsubscripted word expansion expands to the first element of an array.
> 
> Chet
> 
> -- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> 
> Chet Ramey, ITS, CWRU[EMAIL PROTECTED]   
> http://tiswww.tis.case.edu/~chet/
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20915715.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: passing array to command line argument.

2008-12-09 Thread Chet Ramey
Dolphin06 wrote:
> Hello,
> So how can i pass the entire array, i m new to shell scripting so i do not
> really understand when you talk about unsubscripted word expansion

Since programs only take a list of strings as arguments, you have to expand
the array to a list of values.  The "[EMAIL PROTECTED]" expansion can do that.
Expanding an array variable without using a subscript (${array} as opposed
to ${array[subscript]}) expands to the first element.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




Re: passing array to command line argument.

2008-12-09 Thread Stephane Chazelas
On Tue, Dec 09, 2008 at 09:14:51AM -0500, Chet Ramey wrote:
> > 
> > Hello i would like to pass an array to my script command line argument, but
> > only the first element of the array is displayed.  Here is my process :
> > 
> > script1:
> > my_array=(el1 el2 el3)
> > script2 -f $my_array
> 
> You're only passing the first element of the array to script2.  An
> unsubscripted word expansion expands to the first element of an array.
[...]

More exactly, an unsubscripted word expansion expands to the
element of subscript 0 or to the empty string if that element is
not defined.

After

a[12]=foo

The first element is "foo", but $a expands to the empty string.

$a is a shortcut for ${a[0]} and a=bar is a shortcut for a[0]=bar 

This is similar to ksh but different from zsh where arrays and
scalars are of different types, and arrays are not scarse arrays
but normal arrays. In zsh, a[12]=foo allocates an array of 12
elements, the first 11 being empty; $a is the same as $a[*] and
is the list of non-empty elements in $a. Doing a=foo, would
change the type of $a to be a scalar, so you'd lose all the
array elements. The OP's code is actually zsh (or rc/es) syntax,
though it would make more sense to do:

scalar -f "[EMAIL PROTECTED]"

which would work the same in bash, ksh93 and zsh (and in zsh, it
wouldn't discard the empty elements, contrary to $my_array).

-- 
Stéphane




Re: passing array to command line argument.

2008-12-09 Thread Dolphin06

I did the change but i still have only the first element displaying.  I must
say that i m using ssh to call script2 on remote server so maybe it is the
problem :

script1

ssh [EMAIL PROTECTED] script2 -f [EMAIL PROTECTED] -d [EMAIL PROTECTED]

and on script2 it only echoes the first element of both arrays.


Chet Ramey wrote:
> 
> Dolphin06 wrote:
>> Hello,
>> So how can i pass the entire array, i m new to shell scripting so i do
>> not
>> really understand when you talk about unsubscripted word expansion
> 
> Since programs only take a list of strings as arguments, you have to
> expand
> the array to a list of values.  The "[EMAIL PROTECTED]" expansion can do that.
> Expanding an array variable without using a subscript (${array} as opposed
> to ${array[subscript]}) expands to the first element.
> 
> Chet
> 
> -- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> 
> Chet Ramey, ITS, CWRU[EMAIL PROTECTED]   
> http://cnswww.cns.cwru.edu/~chet/
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20916101.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





vi editing mode + color prompt = trouble?

2008-12-09 Thread Halim Issa
On bash 3.2 patchlevel 048 (and earlier) there appears to be problems in vi 
mode and prompts containing escape characters (such as to get bold text).

To reproduce:
Enter vi editing mode set -o vi

Set the following prompt:
export PS1="[\!] [EMAIL PROTECTED]:\w>"

Type "one two three four five six seven eight" press ESCape and 7 B to go 
seven words back. This takes me right in the middle of the prompt while 
displaying (args:7) on the prompt. Once it removes the (args:7) info, ie when 
I press the "B", the cursor location is messed up and I end up in the middle 
of the prompt, instead of at the word "two" where I should be.

Ofcourse it doesn't have to be 7 B, any numbered vi command that displays the 
(args:) feedback will cause things to go wrong with this prompt...

Thanks for reading. Please advise if I chose the wrong channel of reporting.




Re: passing array to command line argument.

2008-12-09 Thread Dolphin06

I dont get it right, i always display only the first one, and i dont know how
to write a scalar variable.
I tried like this :
ssh [EMAIL PROTECTED] script2 -f "[EMAIL PROTECTED]"

It's not changing anything.
I m using bash.
Thank you.

Stephane Chazelas wrote:
> 
> On Tue, Dec 09, 2008 at 09:14:51AM -0500, Chet Ramey wrote:
>> > 
>> > Hello i would like to pass an array to my script command line argument,
>> but
>> > only the first element of the array is displayed.  Here is my process :
>> > 
>> > script1:
>> > my_array=(el1 el2 el3)
>> > script2 -f $my_array
>> 
>> You're only passing the first element of the array to script2.  An
>> unsubscripted word expansion expands to the first element of an array.
> [...]
> 
> More exactly, an unsubscripted word expansion expands to the
> element of subscript 0 or to the empty string if that element is
> not defined.
> 
> After
> 
> a[12]=foo
> 
> The first element is "foo", but $a expands to the empty string.
> 
> $a is a shortcut for ${a[0]} and a=bar is a shortcut for a[0]=bar 
> 
> This is similar to ksh but different from zsh where arrays and
> scalars are of different types, and arrays are not scarse arrays
> but normal arrays. In zsh, a[12]=foo allocates an array of 12
> elements, the first 11 being empty; $a is the same as $a[*] and
> is the list of non-empty elements in $a. Doing a=foo, would
> change the type of $a to be a scalar, so you'd lose all the
> array elements. The OP's code is actually zsh (or rc/es) syntax,
> though it would make more sense to do:
> 
> scalar -f "[EMAIL PROTECTED]"
> 
> which would work the same in bash, ksh93 and zsh (and in zsh, it
> wouldn't discard the empty elements, contrary to $my_array).
> 
> -- 
> Stéphane
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/passing-array-to-command-line-argument.-tp20914576p20918475.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: passing array to command line argument.

2008-12-09 Thread Andreas Schwab
Dolphin06 <[EMAIL PROTECTED]> writes:

> I dont get it right, i always display only the first one, and i dont know how
> to write a scalar variable.
> I tried like this :
> ssh [EMAIL PROTECTED] script2 -f "[EMAIL PROTECTED]"

This passes every element of my_array as a separate argument.  Also, ssh
causes the command line to be parsed a second time on the remote host,
so you have use two levels of quotes.

$ ssh [EMAIL PROTECTED] script2 -f "'${my_array[*]}'"

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Readline redisplay bug with long prompt

2008-12-09 Thread Andreas Schwab
Configuration Information [Automatically generated, do not change]:
Machine: powerpc
OS: linux-gnu
Compiler: gcc -I/usr/src/packages/BUILD/bash-3.2 
-L/usr/src/packages/BUILD/bash-3.2/../readline-5.2
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='powerpc-suse-linux-gnu' 
-DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -O2 -fmessage-length=0 -Wall 
-D_FORTIFY_SOURCE=2 -fstack-protector -g -D_GNU_SOURCE -DRECYCLES_PIDS -Wall -g 
-std=gnu89 -Wextra -Wno-unprototyped-calls -Wno-switch-enum -pipe -fPIE 
-fprofile-use
uname output: Linux igel 2.6.28-rc7 #1 SMP Tue Dec 2 20:12:19 CET 2008 ppc64 
ppc64 ppc64 GNU/Linux
Machine Type: powerpc-suse-linux-gnu

Bash Version: 3.2
Patch Level: 48
Release Status: release

Description:
Redisplay fails if the prompt wraps around and contains invisible
characters after the wrap point.

Repeat-By:
(assuming 80 column display)
$ 
PS1='xxx\$\[\033[0m\]
 '
Cycle back and forth through the history.  Eventually readline
miscounts the four invisible characters at the end of the prompt.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."