Re: Feature Request: Python-like string split and join

2021-01-23 Thread William Park
On Sun, Jan 24, 2021 at 11:29:46AM +0800, Koichi Murase wrote:
> 2021年1月24日(日) 10:22 William Park :
> Is there a background for choosing a semicolon to split words? Zsh has
> a similar feature with a different syntax:

I'm running out of special characters, and I don't want another operator
or syntax that I can't remember 2 weeks from now. :-) That's my main
issue with Zsh.

-- 
William Park 



Feature Request: Python-like string split and join

2021-01-23 Thread William Park
If separator is a single character, then shell can split a string or
join arguments.  But, if separator is string, then it gets messy.  We
shouldn't have to resort to Awk/Python for that.

How about Python-like string split and string join?

${parameter...} is overloaded as is, and we are running out of special
characters.  So, how about, just appending at the end of parameter
expansion syntax?  
${parameter...;sep}
where 
${parameter...} is already existing expansion, and
sep is substring to join, if ${parameter...} is multiple argument
syntax involving '*', like ${*}, ${*:10:10}, ${array[*]:20}, and
sep is substring to split on, if ${parameter...} is single string
syntax like ${var}, ${var:3:10}, ${1}, ${10:2:4}

Eg.
array=( "${var;.}" )
would be equivalent to
IFS=. read -a array <<< "$var"

Eg.
echo "${*;.}"
would be equivalent to
(IFS=.; echo "$*")

Where it would be used?
- everywhere

Advantage?
- replaces multiple lines in shell function
- makes Bash script simpler and clearer
- less bookkeeping and less mistakes

-- 
William Park 



Re: Feature Request: scanf-like parsing

2021-01-22 Thread William Park
On Fri, Jan 22, 2021 at 09:57:15AM -0500, Daniel Colascione wrote:
> On 1/22/21 9:54 AM, Saint Michael wrote:
> > I vote for this new feature.
> 
> Personally, I've found that scanf underpowered for parsing modern data
> formats. Bash's existing regular expression support seems perfectly adequate
> to me, and it can handle everything that scanf can. I'd only suggest
> extending the regular expression syntax with support for named subgroups.

Ah.. I forgot Bash now has regex.  Just tried =~, and I can get the
subgroups out.  Request withdrawn. :-)
-- 
William Park 



Feature Request: scanf-like parsing

2021-01-21 Thread William Park
Another feature request:

To parse out simple thing like IP components, you can do something like
IFS=. read a b c d <<< "11.22.33.44"

But, if data are buried in a mess, then it's very labour-intensive to
dig them out.  It might be useful to have scanf()-like feature, where
stdin or string are read and parsed according to the usual format
string.  I guess, it would actually be sscanf(), since 'read' builtin
reads a line first.  Since you're dealing with strings, only %s, %c, and
%[] are sufficient.

Where it would be used:
- everywhere, really everywhere.  

Advantage:
- You can concentrate on "business logic", and less time on
      bookkeeping.

-- 
William Park 



Feature Request: C struct-like template

2021-01-14 Thread William Park
Here is another feature request.

In C struct, eg.
struct {
char date[7], dev[16], ver[32], rev[10], ...
}
you just access variables, and compiler will do the offsetting.  I would
like something like that, where I don't have to do the bookkeeping.

Right now, I am doing
set -- ...break into arguments...
and access $1, $2, ..., ${@:20:32}, ...  Or,
read -a tokens
and acess tokens[0], tokens[1], ...
This is fine for few arguments, but when it goes to few hundreds, it's
very easy to make mistakes and very difficult to catch it.

So, how about C-like struct template to put your arguments into?

You can build the template like
template=(
date 7
dev 16
ver 32
rev 10
...
)
and it will put the first 7 arguments into array "date", next 16
arguments into array "dev", next 32 arguments into array "ver", next 10
arguments into array "rev", ...

Then, I just use variable "rev" and that would be equivalent to
${@:55:10}.

Where it would useful?  
- parsing real-life CSV files
- parsing UDP packets, for prototyping.
- parsing anything that has fixed width format.
- ...
-- 
William Park 



declare -p name=value thinks 'name=value' is variable

2021-01-08 Thread William Park
Another issue I came across.

declare -p name=value

thinks 'name=value' is the variable.  My reading of manpage seems to say
'name' should be used, but not sure.  Is this a bug?  

Workaround is, of course, use separate lines,
declare name=value
declare -p name
-- 
William Park 



local -p var prints nothing

2021-01-08 Thread William Park
I don't know if it's a bug.  Manpage says "local" builtin takes all the
options that "declare" takes.  But, "local -p var" doesn't print
anything, where as "declare -p var" does.

f1()
{
local a=123
local -p a
}

f2()
{
local a=123
declare -p a
}

f1  # prints nothing
f2  # prints $a

-- 
William Park 



Feature Request: stack

2020-12-28 Thread William Park
I have feature request: stack variable.  Almost like current DIRSTACK
with 'pushd' and 'popd', but for regular arrays.

I know it can be implemented with array, where you push and pop from the
end.  But, a real stack is better.
-- 
William Park 



BASH_ARGV -- arguments are reversed

2014-11-27 Thread William Park
Hi all,

I just noticed that BASH_ARGV contains commandline arguments in reverse.

$ cat  x.sh
#!/bin/sh
declare -p BASH_ARGV
^D

$ sh x.sh 1 2 3 4 5
declare -a BASH_ARGV='([0]=5 [1]=4 [2]=3 [3]=2 [4]=1)'
-- 
William



Re: Bug/limitation in 'time'

2013-03-16 Thread William Park
On Sat, Mar 16, 2013 at 10:15:50PM -0400, Chris F.A. Johnson wrote:
 On Sun, 17 Mar 2013, Chris Down wrote:
ExprCount() {
for (( i = $1 ; i  0 ; i-- )); do
:
done
echo $1 iterations
}
 
Or, in a POSIX-compliant manner:
 
 ExprCount() {
   i=$1
   while [ $(( i -= 1 )) -ge 0 ]; do
 :
   done
   echo Just did $1 iterations using expr math
 }

Are you saying that

for (( ; ; ))

is not POSIX?
-- 
William



Re: Encrypted bashrc?

2011-11-11 Thread William Park
On Fri, Nov 11, 2011 at 04:35:32PM +0800, Clark J. Wang wrote:
 On Fri, Nov 11, 2011 at 2:25 PM, William Park opengeome...@yahoo.ca wrote:
 
  On Fri, Nov 11, 2011 at 01:48:59PM +0800, Clark J. Wang wrote:
   In my company all the people share a few of Solaris servers which use
   NIS to manage user accounts. The bad thing is that some servers' root
   passwords are well known so anybody can easily su to my account to
   access my files.  To protect some private info in my bashrc I want to
   encrypt it. Any one has a good solution for that?
 
  From top of my head:
 1. gpg
 2. openssl
 
 
 I've ever tried openssl and it worked fine overall. The big problem is that
 every time I log in or create a new shell window in screen I have to enter
 my key to decrypt the rc file. I usually open 10 shell windows in screen so
 it's really annoying. More elegant solution?

Well, yes.  But, having passphrase visible for others to see would
defeat the purpose, no?

-- 
William



Re: Encrypted bashrc?

2011-11-10 Thread William Park
On Fri, Nov 11, 2011 at 01:48:59PM +0800, Clark J. Wang wrote:
 In my company all the people share a few of Solaris servers which use
 NIS to manage user accounts. The bad thing is that some servers' root
 passwords are well known so anybody can easily su to my account to
 access my files.  To protect some private info in my bashrc I want to
 encrypt it. Any one has a good solution for that?

From top of my head:
1. gpg
2. openssl
-- 
William



Re: Bug fix for $((x**y)) algorithm on 64+ bits machines.

2011-09-18 Thread William Park
No.  For example, current Bash is copyrighted and licensed by the copyright 
holder.

To get included in Bash, though, I think the license should be the same as Bash,
at the least.
-- 

William



- Original Message -
 From: Nicolas ARGYROU na...@yahoo.com
 To: Dave Rutherford d...@evilpettingzoo.com
 Cc: bashbug bug-bash@gnu.org
 Sent: Saturday, September 17, 2011 11:35:08 PM
 Subject: Re: Bug fix for $((x**y)) algorithm on 64+ bits machines.
 
 You're right. Then, just do what you want with this piece of code, I make it 
 public domain: no restriction at all on using it. It's a gift to bash as I 
 use it a lot. I also accept that you put my name and/or email with the piece 
 of 
 code in case someone wants to contact the author. :-)
 
 Regards,
   Nicolas Argyrou
 
 
 
 - Original Message -
 From: Dave Rutherford d...@evilpettingzoo.com
 To: Nicolas ARGYROU na...@yahoo.com
 Cc: 
 Sent: Saturday, September 17, 2011 10:34 PM
 Subject: Re: Bug fix for $((x**y)) algorithm on 64+ bits machines.
 
 On Sat, Sep 17, 2011 at 07:10, Nicolas ARGYROU na...@yahoo.com wrote:
 
  I came up with a version that is slightly more precise in the comments, and 
 that uses 3 registers instead of 4
  (though gcc can optimize that):
 
 
  // Copyright 2011: Nicolas Argyrou na...@yahoo.com, public domain.
 
 My understanding is that something can be either copyrighted or
 public domain, but not both at the same time. You might want
 to check on this.
 
 Dave




Re: Bug fix for $((x**y)) algorithm on 64+ bits machines.

2011-09-16 Thread William Park
145557834293068928043467566190278008218249525830565939618481
is awfully big number! :-)
-- 
William



- Original Message -
 From: Nicolas ARGYROU na...@yahoo.com
 To: bug-bash@gnu.org bug-bash@gnu.org
 Cc: 
 Sent: Friday, September 16, 2011 4:39:41 PM
 Subject: Bug fix for $((x**y)) algorithm on 64+ bits machines.
 
 From: na...@yahoo.com
 To: bug-bash@gnu.org
 Subject: Bug fix for $((x**y)) algorithm on 64+ bits machines.
 
 Configuration Information [Automatically generated, do not change]:
 Machine: x86_64
 OS: linux-gnu
 Compiler: gcc
 Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
 -DCONF_OSTYPE='linux-gnu' 
 -DCONF_MACHTYPE='x86_64-mandriva-linux-gnu' 
 -DCONF_VENDOR='mandriva' -DLOCALEDIR='/usr/share/locale' 
 -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include 
 -I./lib   -O2 -g -pipe -Wformat -Werror=format-security 
 -Wp,-D_FORTIFY_SOURCE=2 
 -fexceptions -fstack-protector --param=ssp-buffer-size=4
 uname output: Linux localhost.localdomain 2.6.31.14-desktop-1mnb #1 SMP Wed 
 Nov 
 24 10:42:07 EST 2010 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 6000+ 
 GNU/Linux
 Machine Type: x86_64-mandriva-linux-gnu
 
 Bash Version: 4.0
 Patch Level: 33
 Release Status: release
 
 Description:
     The algorithm used to calculate x to the power of y: x**y
     takes O(y) time which is way too long on systems using 64 bits.
     Calculating for exemple $((3**2**62)) freezes the shell at
     argument parsing time.
 
 Repeat-By:
     bash -c 'echo $((3**2**62))'
 
 Fix:
     This fix uses an alorithm that takes O(log(y)) time, which is way
     faster. But it is still about 30 times slower with random numbers
     than a single multiplication, on 64 bits systems. The fix is written
     as a C++ template working on any unsigned integer type, and doesn't
     need any external resource:
 
 // Copyright 2011: Nicolas Argyrou na...@yahoo.com, public domain.
 templatetypename T
 inline T ipow(register T x, register T y)
 {
     if (x == 0  y != 0) return 0;
     // 1: ipow(x,y) = x ** y = Product [i=0; ilog2(y)] (x ** 
 (((yi)1)*2**i))
     // 2: x**(2**i) = x**(2**(i-1)) * x**(2**(i-1))
     register T X = x; register T xy = 1;
     for(; y; y=1, X *= X)
         if (y  1)
             xy *= X;
     return xy;
 }




Re: Why `echo -n hello | while read v; do echo $v; done' prints nothing?

2010-12-02 Thread William Park
On Thu, Dec 02, 2010 at 11:33:24AM -0500, Greg Wooledge wrote:
 On Thu, Dec 02, 2010 at 09:29:29AM -0700, Eric Blake wrote:
  On 12/02/2010 04:04 AM, Clark J. Wang wrote:
   Following command also prints nothing, confused :(
   
   for ((i = 0; i  10; ++i)); do echo -n  $i; done | while read v; do echo
   $v; done
  
  http://www.faqs.org/faqs/unix-faq/shell/bash/
  FAQ E4.
 
 That was my first thought as well, upon first glance.  But that's not
 the actual problem here.  It's the lack of newline causing read to return
 'failure' even though it does read the input.

Yeah, it has bitten me too many times.  I keep forgetting it though.

-- 
William



Re: Help with sed

2010-04-17 Thread William Park
On Fri, Apr 16, 2010 at 01:22:24AM -0700, Radim wrote:
 
 Hello,
 I have such script:
 
 (ONLY THIS THREE LINES ARE THE COMMANDS )
 content=$(cat $script | sed  '/function codecs/,/fi;/d');
 content=$(echo $content | sed -n '/mandriva/,/fi;}/p');
 content=$(echo $content | sed  '/^\s*urpmi[:space:]--auto/p');
 
 But it doesn't work as I would expected.
...
 What I try to do:
 1) To delete the codecs function of the output.
 2) To get the if mandriva block
 3) from that block to get lines of urpmi
 
 Anybody help?

Key insight would be 

content=$(cat $script | sed ...)
echo $content  x

Look at x, and see what you got.  Why not just put all 3 sed
filters in a pipe?

-- 
William





Re: bash 4.x filters out environmental variables containing a dot in the name

2009-06-28 Thread William Park

Thanks for heads up, Christian.  Filtering out . will break our company's 
accounting software, and presumably many other applications.

Checking for correct charset is sensible thing to do when setting or accessing 
a variable.  But, those variables that Bash did not change or set, should be 
passed on to the next program untouched.

--William

--- On Fri, 6/26/09, Christian Krause c...@plauener.de wrote:

 From: Christian Krause c...@plauener.de
 Subject: Re: bash 4.x filters out environmental variables containing a dot in 
 the name
 To: chet.ra...@case.edu
 Cc: bug-bash@gnu.org
 Received: Friday, June 26, 2009, 7:58 AM
 Hi Chet,
 
 Thanks for the answers. The problem is now, that this
 behavior of the
 bash creates some real problems outside, probably with a
 larger impact.
 Before asking the kernel developers to change parts of
 linux kernel's
 build system, I'd like to be sure whether bash-4.x's
 behavior is correct
 or not. Please see my comments below:
 
 Chet Ramey wrote:
  Mike Frysinger wrote:
  On Thursday 25 June 2009 19:17:38 Chet Ramey
 wrote:
  Christian Krause wrote:
  Bash Version: 4.0
  Patch Level: 16
  Release Status: release
 
  Description:
  During the compilation of the linux kernel
 (configured to user mode
  linux) I've discovered the following
 problem of bash 4.0 (which is now
  delivered by Fedora 11):
 
  If an environmental variable contains a
 . in its name, the new bash
  4.0 filters out these variables. They will
 not be visible via set nor
  will they be inherited to executed
 sub-shells or processes.
  Such strings are invalid shell or environment
 variable names.  It was a
  bug in bash-3.2 that it created invalid
 variables from the initial
  environment.
  and it's a bug that bash-4 is filtering
 them.  not allowing them to be used in 
  the shell is fine (echo ${vmlinux.lds}), but
 removing them from the 
  environment and thus not allowing other
 applications to leverage them is not.  
  
  It's not a bug.  Posix explicitly restricts
 environment variable names
  to consist of uppercase letters, lowercase letters,
 digits, and
 
 As far as I interpret the standard (IEEE Std 1003.1, 2004
 Edition), the
 general definition for environment variables is something
 like this:
 
 - names must not contain =
 - if it should be portable, the names should only contain
 characters
 from the portable character set (which includes .)
 
 Sure, there is a restriction that variables used by the
 shell (and the
 utilities described in the standard) should only contain
 the characters
  you described.
 
 However, since not all programs belong to this set, I don't
 see an
 explicit statement which denies the usage of e.g. . in
 environmental
 variables in general.
 
  underscores.  There is no provision for variables
 with invalid names
  that don't exactly exist and are just passed down to
 applications in
  their environment.  The environment is
 constructed from variables with
  the export attribute set (another thing Posix
 explicitly states); things
  that aren't valid variables don't get in there.
 
 Hm, I'm not sure I can agree to this. The problem is, that
 for other
 programs names of environmental variables containing a .
 are not
 invalid (although they are invalid for the bash).
 
 As far as I understand the behavior of the bash,
 environmental variables
 which were put in the process environmental during exec'ing
 a shell are
 exported to subsequent processes of this shell without
 explicitly
 exporting them.
 So, if the bash passes variables containing in the bash's
 process
 environment to sub-processes anyway (without any explicit
 export), I
 would argue it would be more natural that the bash should
 not filter
 them. If any other process execs itself, the new process
 image will have
 the same environmental variables set (if not execle is
 used)...
 
 Given all of these facts I still tend to say that the bash
 shouldn't
 filter them...
 
 
 Best regards,
 Christian
 
 
 


  __
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
favourite sites. Download it now
http://ca.toolbar.yahoo.com.




Re: feature request

2006-06-05 Thread William Park
On Wed, May 31, 2006 at 04:49:36PM -0500, A P Garcia wrote:
 It would be very useful to have a shell option that displays the exit
 code of each command when it terminates.

I'm currently using

PS1='$? [EMAIL PROTECTED]:\w\$ '

$? is what you are after.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: make 'tr' (or something like it) a bash builtin ?

2006-02-05 Thread William Park
On Sun, Feb 05, 2006 at 07:02:10PM -0500, Chris F.A. Johnson wrote:
 On Sun, 5 Feb 2006, Felipe Kellermann wrote:
 
 On Thu, 2 Feb 2006 11:13pm  -0500, Mike Frysinger wrote:
 
 upper case or lower case ... if 'tr' was a bash builtin, then that'd work
 with some `echo | tr` magic, but it something like
 ${foo//[[:lower:]]/[[:upper:]]} would be nice
 -mike
 
 typeset -u (ksh, zsh) supported in bash would be nice...
 
  orchid% typeset -u fuu

Options are already overloaded.  I could never remember what is what.

 
So long as it uses declare, not typeset :)
 
  orchid% fuu=bar
  orchid% echo $fuu
  BAR
 
I'd prefer variable expansion, perhaps the way Mike suggested, or,
e.g.:
 
 $ foo=bar
 $ echo ${foo^}  ## Convert first character
 Bar
 $ echo ${foo^^}  ## Convert all characters
 BAR
 $ echo ${foo^[a-m]} ## Convert first character that matches pattern
 Bar
 $ echo ${foo^^[a-m]} ## Convert all characters that match pattern
 BAr

I did that, and subsequently removed it because I ran out of
punctuation. :-)

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: incorrect brace expansion

2006-01-29 Thread William Park
On Sun, Jan 29, 2006 at 05:37:56PM -0500, Mike Frysinger wrote:
 On Sunday 29 January 2006 17:25, Bob Proulx wrote:
  The bash manual documents this as Patterns to be brace expanded
  take the form of an optional PREAMBLE, followed by either a series
  of comma-separated strings or a sequnce expression between a pair of
  braces, followed by an optional POSTSCRIPT.  Your example did not
  have either comma-separated strings nor a sequence and therefore
  does not qualify for brace expansion and should have been left
  verbatim.  And yet bash did brace expansion anyway.  That is an
  inconsistency.
 
 a-{b}-c was not brace expanded, ok, good
 
 a-{b{d,e}}-c was expanded too many times ... the output should have
 been a-{bd}-c a-{be}-c ... just cause csh does it differently doesnt
 really matter imo
 
 as you pointed out, the docs say that the brace expansion should only
 happen when commas or sequence expressions are used, and while the
 inner braces used commads, the outer braces did not -mike

Let's see...
a-{b{d,e}}-c
a-{bd,be}-c
a-bd-c a-be-c

It looks okey, I think.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


{-2..2}

2006-01-29 Thread William Park
Hi Chet,

Bash-3.0 introduced {-2..2} syntax which generates -2, -1, 0, 1, 2.
Unfortunately, it clashes with my extension which doesn't do negative
integers; instead, mine was designed for equal width integer, like 00,
01, 02.

Do you plan to keep the negative integer features of {a..b}?

This is the only conflict between your standard Bash and my extensions.
If you're keeping it, then I'll change syntax on my end.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: incorrect brace expansion

2006-01-29 Thread William Park
On Sun, Jan 29, 2006 at 07:33:14PM -0500, Chris F.A. Johnson wrote:
 On Sun, 29 Jan 2006, William Park wrote:
 Let's see...
a-{b{d,e}}-c
a-{bd,be}-c
a-bd-c a-be-c
 
 It looks okey, I think.
 
 Except that b{d,e} expands to 'bd be', not 'bd,be'.

Hmm... no.  Internally, {d,e} gets converted to array of 2 strings, ie.
array[0] = d;
array[1] = e;
Then, prefix and suffix are attached.  So, when prefix 'b' is attached,
you have
array[0] = bd;
array[1] = be;
This continues recursively (left to right, I believe).

When you attach the second prefix 'a-' and suffix '-c', the results are
array[0] = a-bd-c;
array[1] = a-be-c;
Now, you can argue that suffix/prefix are 'a-{' and '}-c', in which
case, you get 
array[0] = a-{bd}-c;
array[1] = a-{be}-c;

I think, it's matter of taste. :-)

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: arithmetic operations

2006-01-24 Thread William Park
On Tue, Jan 24, 2006 at 05:58:49PM +0300, Alexander Kshevetskiy wrote:
 Configuration Information [Automatically generated, do not change]:
 Machine: i686
 OS: linux-gnu
 Compiler: i686-pc-linux-gnu-gcc
 Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
 -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
 -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
 -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -O2 -march=athlon-xp 
 -fomit-frame-pointer
 uname output: Linux radio 2.6.14-gentoo-r2 #3 PREEMPT Wed Dec 14 22:38:58 MSK 
 2005 i686 AMD Athlon(TM) XP 1600+ AuthenticAMD GNU/Linux
 Machine Type: i686-pc-linux-gnu
 
 Bash Version: 3.1
 Patch Level: 5
 Release Status: release
 
 Description:
 
 1)
 let a=(a+500)/1000
 does not work after update from 3.0 to 3.1, while
 let a=\(a+500\)/1000
 is working

You should quote that expression, like
let 'a=...'

 
 2)
 a=8000; a=$[(a+500)/1000]; --- 9

Shouldn't that be $((...)) ?

 a=8000; let a=\(a+500\)/1000; --- 8
 
 this way, we can show that 2x2=3.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Visual completion ellipsis

2005-12-10 Thread William Park
On Sat, Dec 10, 2005 at 11:36:53PM +0100, Grzegorz Adam Hankiewicz wrote:
 Nearly a month later, despite a lack of instructions, I manage to
 subscribe to this mailing thanks to the answers of Bob Proulx and
 Chet Ramey. Lurking here, I see no trace of active development,
 no information about the process of submitting patches, no real
 hint of what somebody would have to do to contribute one...

Bash and Readline are written by Chet Ramey.  So, give the guy a break.
He's too busy fixing bugs.  :-)

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: reciproc pipe()

2005-09-04 Thread William Park
Robert Millan [EMAIL PROTECTED] wrote:
 
 Hi!
 
 Is there any way to tell bash to do something like this?  If there isn't, I
 think it would be nice to have it (maybe through a builtin or something).
 
 int p1[2];
 int p2[2];
 
 pipe(p1);
 pipe(p2);
 
 if (fork () == 0)
   {
 close (0); dup (p1[0]);
 close (1); dup (p2[1]);
 exec(whatever);
   }
 
 if (fork () == 0)
   {
 close (0); dup (p2[0]);
 close (1); dup (p1[1]);
 exec(whatever);
   }
 
 I.e, each process communicates with the other via stdin/stdout, and we get the
 actual results via stderr.

Where would you use it?

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
.


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: IFS=$'\xb2'

2005-08-06 Thread William Park
On Sat, Aug 06, 2005 at 10:00:07AM -0400, Chris F.A. Johnson wrote:
 IFS=$'\xb2' ; with the same results.
  I cannot reproduce this bug in 3.00.16(1)-release. I am using
  Mandrive LE2005, but I compiled my own bash.

I tried it on Bash-2.05b/3.0, and I don't get segfault.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: jobs not working in bash scripts (?)

2005-07-22 Thread William Park
On Fri, Jul 22, 2005 at 01:50:49PM +0200, Rainer Dorsch wrote:
 Hello,
 
 I was debugging a larger script, and found that the buildtin jobs command 
 does 
 not work in bash scripts, altough it does in an interactive shell:
 
 [EMAIL PROTECTED]:~/tmp.nobackup$ cat testjob
 #!/bin/bash
 
 sleep 35 
 jobs -p %%
 [EMAIL PROTECTED]:~/tmp.nobackup$ ./testjob
 [EMAIL PROTECTED]:~/tmp.nobackup$ . testjob
 17825
 [EMAIL PROTECTED]:~/tmp.nobackup$
 
 It might be a feature, in the man page, I read:
 
The symbols  %%  and
%+  refer  to  the shell's notion of the current job, which is the last
job stopped while it was in the foreground  or  started  in  the  back-
ground.
 
 ...but I don't read out of that that it does not work in a non-interactive 
 shell.
 
 I know it worked before in that script and ksh does not make a difference 
 between interactive and non-interactive shell. But I don't know
 
 Any comments are welcome.

See if 
set -m
makes any difference.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: (announce) GTK+2 + Bash

2005-07-13 Thread William Park
On Mon, Jul 11, 2005 at 11:57:38AM -0400, William Park wrote:
 Ref:
 http://freshmeat.net/projects/bashdiff/
 http://home.eol.ca/~parkw/index.html#gtk

More updates.  The documentation now has some snapshots.  The latest
release is BashDiff-1.24.

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


(announce) GTK+2 + Bash

2005-07-11 Thread William Park
For your reading pleasure, this is a copy of what I posted to
comp.unix.shell, and other mandatory cross-posting...


I'm very excited to announce shell interface to GTK+2 (2.6.1) for Bash.
It read XML syntax describing the widget layout, and returns user
selection as shell variable or runs shell command as callback.  It's
designed for simple GUI dialog or layout, with the emphasis on getting
the user data back into shell.

For the moment, the shell variable and command are disabled.  It just
prints to stdout, instead.  But, you can change it easily.


Ref:
http://freshmeat.net/projects/bashdiff/
http://home.eol.ca/~parkw/index.html#gtk

Usage:
gtk  file.xml
gtk file.xml...


For example, GTK+2 tutorial has 2 button 'helloworld2.c',

http://www.gtk.org/tutorial/sec-anupgradedhelloworld.html
http://www.gtk.org/tutorial/images/helloworld2.png

You can now build the same thing with

window border=10 label=Hello Buttons!
hbox
button label=Button 1 clicked=echo Button 1 was pressed /
button label=Button 2 clicked=echo Button 2 was pressed /
/hbox
/window

Or, 

gtk  EOF
window
...
/window
EOF


Feedbacks are welcome.  Enjoy!

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


(submission) patch to 'parse.y'

2005-07-05 Thread William Park
 |= CMD_IGNORE_RETURN;
+
+out = EXECUTION_SUCCESS;
+
+try_level++;
+do {
+   REAP ();
+   QUIT;
+   out = execute_command (try_command-action);
+   QUIT;
+} while (0);   /* run only once */
+try_level--;
+   
+if (exception) {
+   CASE_COM *catch;
+   char *old;
+
+   catch = (CASE_COM *)xmalloc (sizeof (CASE_COM));/* free this */
+   catch-flags = try_command-flags;
+   catch-line = line_number;
+   catch-word = make_bare_word (exception);   /* free this */
+   catch-clauses = try_command-clauses;
+   catch-true_case = (COMMAND *)NULL;
+   catch-false_case = (COMMAND *)NULL;
+   catch-total_match = 0;
+
+   old = exception; 
+   exception = (char *)NULL;   /* so that 'case' statement will run */
+
+   execute_case_command (catch);
+
+   if (exception)  /* new exception raised from 'case' statement */
+   FREE (old);
+   else if (catch-total_match)/* exception was caught */
+   FREE (old);
+   else if (try_level == 0)/* we reached top level */
+   FREE (old);
+   else/* retore exception, to go further up */
+   exception = old;
+
+   dispose_word (catch-word);
+   FREE (catch);
+}
+
+return (out);
+}
+/**/
diff -rubBP -x autom4te.cache -x '*--old' -x doc -x po -x configure -x parse.c 
../bash-3.0/execute_cmd.c ../bash/execute_cmd.c
--- ../bash-3.0/execute_cmd.c   2004-07-04 14:12:58.0 -0400
+++ ../bash/execute_cmd.c   2005-06-09 23:32:55.0 -0400
@@ -95,6 +95,14 @@
 #  include bashhist.h
 #endif
 
+
+/* --William */
+#include builtins/subroutines.h
+extern char *exception;
+extern int try_level;
+static int execute_try_command __P((TRY_COM *));
+
+
 extern int posixly_correct;
 extern int breaking, continuing, loop_level;
 extern int expand_aliases;
@@ -382,6 +390,7 @@
 case cm_case:
 case cm_while:
 case cm_until:
+case cm_try:   /* --William */
 case cm_if:
 case cm_group:
   return (1);
@@ -494,7 +503,7 @@
   volatile pid_t last_pid;
   volatile int save_line_number;
 
-  if (command == 0 || breaking || continuing || read_but_dont_execute)
+  if (command == 0 || breaking || continuing || read_but_dont_execute || 
exception /* --William */)
 return (EXECUTION_SUCCESS);
 
   run_pending_traps ();
@@ -766,6 +775,12 @@
   exec_result = execute_until_command (command-value.While);
   break;
 
+case cm_try:   /* --William */
+  if (ignore_return)
+   command-value.Try-flags |= CMD_IGNORE_RETURN;
+  exec_result = execute_try_command (command-value.Try);
+  break;
+
 case cm_if:
   if (ignore_return)
command-value.If-flags |= CMD_IGNORE_RETURN;
@@ -1578,9 +1593,38 @@
   SHELL_VAR *old_value = (SHELL_VAR *)NULL; /* Remember the old value of x. */
 #endif
 
+  WORD_LIST *multi_variables, *mv; /* --William */
+
   save_line_number = line_number;
+
+  
/*
+   * Enable multiple loop variables in for-loop, with syntax
+   *   for  a,b,c,...  in list; do
+   *   ...
+   *   done
+   * where no space is allowed around ',' (comma) because only one word is
+   * parsed.  List items are sequentially assigned to the loop variables 'a',
+   * 'b', 'c', etc.  If there is shortage of item, then the last iteration will
+   * run with '' (null) assigned to leftover variables.
+   *
+   * --William Park
+   */
+  multi_variables = (WORD_LIST *)NULL;
+
+  if (xstrchr (for_command-name-word, ',') != NULL) {/* 
split 'a,b,c,...' */
+  /* word_split() breaks up word, only if it's not quoted.  It's front-end
+   * to list_string() for WORD_DESC variable. */
+  multi_variables = word_split (for_command-name, ,);
+
+  for (mv = multi_variables; mv; mv = mv-next)
+ if (check_identifier (mv-word, 1) == 0) {
+ dispose_words (multi_variables);
+ goto Exit_by_Original_Code;
+ }
+  } else { /* original code */
   if (check_identifier (for_command-name, 1) == 0)
 {
+Exit_by_Original_Code: /* --William */
   if (posixly_correct  interactive_shell == 0)
{
  last_command_exit_value = EX_USAGE;
@@ -1588,6 +1632,8 @@
}
   return (EXECUTION_FAILURE);
 }
+  }
+  
//
 
   loop_level++;
   identifier = for_command-name-word;
@@ -1638,9 +1684,35 @@
 #endif
 
   this_command_name = (char *)NULL;
+ 
+  
/*
+   * Assign list items into a, b, c, ...   --William
+   */
+  if (multi_variables) {
+ for (mv = multi_variables; mv; mv = mv

Re: (feature request) here-document, but from a file

2005-07-03 Thread William Park
On Sat, Jul 02, 2005 at 11:43:36PM -0400, Chet Ramey wrote:
 Chris F.A. Johnson wrote:
  On Sat, 2 Jul 2005, William Park wrote:
  
  Dear Chet,
 
  It would be nice if I can read a file and process it as though it was
  here-document text in the script.  Mainly, I want variable substitution,
  without calling lots of 'sed'.
 
  In Python, you would do
 print ... % ...
 
  So, perhaps, you can use syntax like
 cat + file
 cat  file
  
  
  Why can't you use:
  
  cat  file
 
 Because he wants variable substitution.  Something like
 
 cat  $( file)
 
 might work.

Darn it, it does work.  Argghh... I already included a here-file patch
with my latest release:
http://home.eol.ca/~parkw/index.html#herefile
http://home.eol.ca/~parkw/index.html#here_file

Usage:
cat  file
herefile  file
herefile file


Hi Chet.  Off topic... I'm currently considering adding GTK+ interface
to Bash, so that you can do basic dialog stuff in Bash directly.  But,
if it's only dialog stuff, then there isn't much point, because you can
just use real 'dialog' or 'Xdialog'.

Have you come across any project that tries to add GUI features to any
shell?

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Updated fix of array_rshift() in array.c

2005-05-31 Thread William Park
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib   -O4
uname output: Linux node1 2.6.11-smp #2 SMP Thu Mar 3 09:53:04 EST 2005 i686 
unknown unknown GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 3.0
Patch Level: 0
Release Status: release

Description:
It's not visible to user.  But, I remember submitting a fix for
this problem.  Here is an updated patch.

In array_rshift() in array.c, 'max_index' is incremented, even
if array is empty.  So, if shift is greater than 1 (say, 5),
then 'max_index' will end up being fictitious.  You won't be
able to insert any item from 1 to 5.  You have to insert at
index greater than 5 in order to force 'max_index' to be real
again.  Then, you can insert as normal.

Fix:

--- ../bash-3.0/array.c 2004-05-06 08:24:13.0 -0400
+++ array.c 2005-05-31 16:21:24.0 -0400
@@ -255,7 +255,9 @@
a-num_elements++;
}
 
+#if 0  /* Move to the end.  --William */
a-max_index += n;
+#endif
 
/*
 * Renumber all elements in the array except the one we just added.
@@ -263,6 +265,14 @@
for ( ; ae != a-head; ae = element_forw(ae))
element_index(ae) += n;
 
+   /* Fix:  If array is empty and you shift 5, then 'max_index' increases
+* from -1 to 4.  But, you still have empty array (if S is NULL) or have
+* only element (ie. array[0]=S).  Later on, array_insert() cannot find
+* place to insert for array[1] to array[4].  Adjust 'max_index' after
+* all other indexes have been incremented.  --William
+*/
+   a-max_index = element_index (a-head-prev);
+
return (a-num_elements);
 }
 
@@ -451,7 +461,10 @@
 */
array_dispose_element(new);
free(element_value(ae));
-   ae-value = savestring(v);
+
+   /* Fix: savestring() cannot take NULL argument  
--William */
+   ae-value = v ? savestring(v) : (char *)NULL;
+
return(0);
} else if (element_index(ae)  i) {
ADD_BEFORE(ae, new);


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: bash script problems

2005-05-11 Thread William Park
On Thu, May 12, 2005 at 02:32:42AM +1000, Tony Jo wrote:
 Hello, I am having issues with a bash script and I was wondering if
 anyone could be of assistance? Its just that our lecturer assumed it
 would be easy to pick up and do an assignment on, even though we
 haven't learnt it and its not a pre-requisite.
 
 But anyway, I noticed when I use the cut command to obtain some
 numbers from a file, I cannot use it in an arithmetic operation. I
 tried the following: temp='expr $val1 + $val2' But I get the following
 error message: expr: non-numeric argument
 
 I was wondering if BASH requires type conversion? I even printed out
 the values for $val1 and $val2. They look like integers to me. If
 anyone could help me, it would be greatly appreciated.
 
 Thanks in advance

Note the difference between `...` and '...'

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
 http://home.eol.ca/~parkw/thinflash.html


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Feature semi-request about bash initialization

2005-03-07 Thread William Park
On Mon, Mar 07, 2005 at 08:57:46AM -0500, Steve Simmons wrote:
 A regular problem with most shells is that when logging via the common
 X window logins (xdm and its more modern descendants for cde, gnome, kde,
 etc) the initial shell started is neither interactive nor a login shell.
 Thus logging onto a workstation console gives a considerably different
 initialization process than logging in via ssh.  Here are some of the
 workarounds bash users and system admins are doing to handle this:

I don't understand.  When you log in through XDM (or, KDM, GDM), it runs
~/.xsession
which is usually symlink to ~/.xinitrc, but doesn't have to be.  Then,
you're into your windows manager.  This initial file is run like any
other shell script on your system.

If you're talking about Xterm, then bring it up as
xterm -ls

-- 
William Park [EMAIL PROTECTED], Toronto, Canada
Slackware Linux -- because it works.


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash