Re: [Parameter Expansion] bug in ${variable% *}

2013-02-12 Thread Bernd Eggink
On 12.02.2013 18:50, Dashing wrote: On Tue, 12 Feb 2013 18:02:05 +0100 "Chet Ramey" I've fixed the problem, and the fix will be in the next release. Thank you, Chet! On Tue, 12 Feb 2013 10:13:46 +0100 "Bernd Eggink" superfluous blank in the ${rest: -1} expression

Re: [Parameter Expansion] bug in ${variable% *}

2013-02-12 Thread Bernd Eggink
On 11.02.2013 18:50, Dashing wrote: Bash version: 4.2.042 I have a script that behaves erratically: = #! /bin/bash last=${1##* } rest=${1% *} while [[ "${rest: -1}" == '\' ]]; do last="${rest##* } $last" oldrest=$rest rest=${rest% *} if [[ "$oldrest" == "$

Re: equivalent of Linux readlink -f in pure bash?

2011-08-11 Thread Bernd Eggink
On 09.08.2011 16:54, Stephane CHAZELAS wrote: 2011-08-09, 09:50(-04), Steven W. Orr: [...] *) To remove the trailing slashes, instead of while [[ $file == */ ]] do file=${file%/} done file=${file##*/}# file name jus

Re: equivalent of Linux readlink -f in pure bash?

2011-08-10 Thread Bernd Eggink
On 09.08.2011 15:50, Steven W. Orr wrote: On 8/9/2011 5:29 AM, Bernd Eggink wrote: On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here: http://sudrala.de/en_d/

Re: equivalent of Linux readlink -f in pure bash?

2011-08-09 Thread Bernd Eggink
On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here: http://sudrala.de/en_d/shell-getlink.html As it contains some corrections from Greg Wooledge, it should handle ev

Re: Bash-4.2-rc2 available for FTP

2011-02-02 Thread Bernd Eggink
opposed to 0.2 seconds with 4.1-9. Counting from 1 to 1 is about 20 times slower. Maybe due to heavy debugging? Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Issues when func name is the same with an alias

2010-08-04 Thread Bernd Eggink
Am 04.08.2010 16:38, schrieb Clark J. Wang: On Wed, Aug 4, 2010 at 8:27 PM, Bernd Eggink wrote: Am 04.08.2010 12:39, schrieb Clark J. Wang: I was testing the precedence between functions and aliases so I tried like this (with bash 4.1.5): $ cat rc alias foo='echo this is the alias&

Re: Issues when func name is the same with an alias

2010-08-04 Thread Bernd Eggink
pts): http://www.chiark.greenend.org.uk/~sgtatham/aliases.html Interesting article. One thing not mentioned there is declarations. alias assoc='declare -A ' assoc x y z Not particularly useful, but you can't replace that with a function (as long as there is no 'global' option for decl

Re: Issues when func name is the same with an alias

2010-08-04 Thread Bernd Eggink
mand, if unquoted, is checked to see if has an alias". Therefore 'foo' in your function declaration is replaced by 'echo this is the alias'. Unfortunately, you can't quote the function name in the declaration, so you have to either use 'function' or say "unalias foo" first. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: RFE? request for an "undefined" attribute for functions

2010-08-02 Thread Bernd Eggink
Am 02.08.2010 20:16, schrieb Eric Blake: On 08/02/2010 12:15 PM, Bernd Eggink wrote: Am 02.08.2010 19:15, schrieb Andreas Schwab: Bernd Eggink writes: eval "function $name Don't use function, use "$name ()" instead. What's wrong with function??

Re: RFE? request for an "undefined" attribute for functions

2010-08-02 Thread Bernd Eggink
Am 02.08.2010 19:15, schrieb Andreas Schwab: Bernd Eggink writes: eval "function $name Don't use function, use "$name ()" instead. What's wrong with function?? Bernd -- Bernd Eggink http://sudrala.de

Re: RFE? request for an "undefined" attribute for functions

2010-08-02 Thread Bernd Eggink
toload f1 f2 f3' in ksh) creates small placeholder functions f1, f2, and f3. The first call to any of these functions will replace its definition by the one found in $FUNCDIR, and also call the latter. I'm not sure, however, if this is guaranteed to work in any case (and in any bash version). Greetings, Bernd -- Bernd Eggink http://sudrala.de

Re: weird behaviour of ((count++)) when using , , to change to lower case

2010-08-01 Thread Bernd Eggink
t this to print "monday, monday, tuesday", since you left out the ++ in the first term. I think the problem is that the ,, operator causes each expression to be evaluated twice. That would explain this behaviour, and it's a bug IMHO. Regards, Bernd -- Bernd Eggink http://sudrala.de

Indirect expansion and arrays

2010-07-29 Thread Bernd Eggink
ere is only a choice between passing all elements to a function, which is time-consuming, or using eval, which is cumbersome and error-prone. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: function grammar

2010-07-19 Thread Bernd Eggink
[ function ] name () compound-command [redirection] and do not see the version you show without the parens. It's there. Look at the 3rd sentence: "If the function reserved word is supplied, the parentheses are optional." Bernd -- Bernd Eggink http://sudrala.de

Re: [bash-bug] parsing error with heredoc and command substitution

2010-07-15 Thread Bernd Eggink
Am 15.07.2010 10:35, schrieb Andreas Schwab: "Dr. Werner Fink" writes: a=$((/bin/cat|wc -l)< Useless subshell. a=$({ /bin/cat | wc -l; }< ...and useless cat: a=$(wc -l <Nevertheless, IMHO the OP's version should work. It works in ksh, for example. Ber

Wrong alignment in select lists

2010-05-31 Thread Bernd Eggink
}; do :; done# wrong select x in amö blah{1..20}; do :; done # OK Bash version is 4.1.7(1)-release, LANG is de_DE.UTF-8. Bernd -- Bernd Eggink http://sudrala.de

Re: create array in loop with variable in array's name

2010-05-29 Thread Bernd Eggink
c) ; what means that first element of array1[0]="a" and for example third element of array3[2]="c". This is the way how I do it : for (( n=1; n<4; n++ )) do array$n=(a b c) done ...but there is syntax error That's because array$n isn't a valid name. Use eval:

Re: Is there a special variable for the directory where the script is in?

2010-02-12 Thread Bernd Eggink
Am 12.02.2010 15:39, schrieb Greg Wooledge: On Fri, Feb 12, 2010 at 02:53:39PM +0100, Bernd Eggink wrote: I once wrote a more generic shell function for this purpose, see: http://sudrala.de/en_d/shell-getlink.html You note that it doesn't handle names containing ->, which is true.

Re: Is there a special variable for the directory where the script is in?

2010-02-12 Thread Bernd Eggink
once used some ls -l "$SCRIPTS" | sed -e 's/.* -> //' magic to replace it (and it worked two minutes ago on the HP-UX, just like it used to back in the old days). I once wrote a more generic shell function for this purpose, see: http://sudrala.de/en_d/shell-getlink.html Bernd -- Bernd Eggink http://sudrala.de

Re: add a way to declare global variables

2009-12-14 Thread Bernd Eggink
Am 12/14/09 13:37, schrieb Marc Herbert: Bernd Eggink a écrit : To avoid misunderstandings, let me add that you are right (only) with respect to variables being used _without_ declaration. OK, but not having to explicitly "declare" variables is a feature that most people expect fr

Re: add a way to declare global variables

2009-12-12 Thread Bernd Eggink
Am 12.12.2009 21:41, schrieb Chet Ramey: On 12/12/09 5:28 AM, Bernd Eggink wrote: Am 10.12.2009 10:40, schrieb konsolebox: I hope the development team will also consider adding a way in bash to declare global variables inside a function perhaps either with an option in typeset or declare like

Re: add a way to declare global variables

2009-12-12 Thread Bernd Eggink
Am 12.12.2009 15:25, schrieb DennisW: On Dec 12, 4:24 am, Bernd Eggink wrote: Am 12.12.2009 02:11, schrieb Matthew Woehlke: konsolebox wrote: I hope the development team will also consider adding a way in bash to declare global variables inside a function perhaps either with an option in

Re: add a way to declare global variables

2009-12-12 Thread Bernd Eggink
Am 12.12.2009 15:25, schrieb DennisW: On Dec 12, 4:24 am, Bernd Eggink wrote: Am 12.12.2009 02:11, schrieb Matthew Woehlke: konsolebox wrote: I hope the development team will also consider adding a way in bash to declare global variables inside a function perhaps either with an option in

Re: add a way to declare global variables

2009-12-12 Thread Bernd Eggink
Am 12.12.2009 11:24, schrieb Bernd Eggink: Am 12.12.2009 02:11, schrieb Matthew Woehlke: konsolebox wrote: I hope the development team will also consider adding a way in bash to declare global variables inside a function perhaps either with an option in typeset or declare like -g (same as zsh

Re: add a way to declare global variables

2009-12-12 Thread Bernd Eggink
second that. I'm missing this feature badly. Presently, you can only get around this restriction by using a lot of ugly and dangerous 'eval's. Bernd -- Bernd Eggink http://sudrala.de

Re: add a way to declare global variables

2009-12-12 Thread Bernd Eggink
t, declare, and local are synonyms. Using 'local' outside a function is an error, so IMHO this command is completely redundant. It _would_ make some sense, however, if its counterpart 'global' existed, as it could help clarify the intended usage of the variable. Bernd -- Bernd Eggink http://sudrala.de

Re: Use of pipe in $(< filename | program) returns null

2009-11-28 Thread Bernd Eggink
ho $qq # result is null Fix: Either fix the docs to tell people that a pipe is not allowed or fix the code to allow it. The problem is not the pipe but the fact that 'command which does nothing. If you want 'program' to read from 'file', use '

Re: Wrong 'declare -A' causes segfault

2009-11-26 Thread Bernd Eggink
Am 26.11.2009 01:47, schrieb Chet Ramey: Bernd Eggink wrote: GNU bash, version 4.0.35(1)-release (i686-pc-linux-gnu) The following syntactically wrong declaration causes a segmentation fault: declare -A x=y It should issue an error message instead. It's not actually a syntax

Wrong 'declare -A' causes segfault

2009-11-25 Thread Bernd Eggink
GNU bash, version 4.0.35(1)-release (i686-pc-linux-gnu) The following syntactically wrong declaration causes a segmentation fault: declare -A x=y It should issue an error message instead. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Strange compgen behaviour

2009-09-25 Thread Bernd Eggink
directory part. After all, 'find -name' matches names, not paths (if you want to match full paths, use 'find -path'). I'd also rather use printf "%P\n" (capital P) instead of %p, the results look nicer (IMHO). Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Strange compgen behaviour

2009-09-24 Thread Bernd Eggink
PLY=($(IFS=: compgen -W "$list")) } complete -F _aha aha Typing aha cycles through 6 items a, b, c, d, e, f, whereas I would expect 3 items 'a b', 'c d', 'e f'. It looks like compgen splits the argument to -W on $IFS _and_ whitespace. Or am I missing

Re: Strange compgen behaviour

2009-09-24 Thread Bernd Eggink
lf. Try this: _mm2() { local cur files cur=${COMP_WORDS[COMP_CWORD]} files=$(find /home/mathias/Videos/movies/ -iname "$cur*.avi" -type f -printf "%P\n") local IFS=$'\n' COMPREPLY=($files) } Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Strange compgen behaviour

2009-09-23 Thread Bernd Eggink
t=$(printf "%s:" /home/mathias/Videos/movies/*) IFS=: compgen -W "$list" -- $zc Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Help with script - doesn't work properly from cron

2009-07-18 Thread Bernd Eggink
-else clause by mkdir -p $CURRENT_DIR cd $CURRENT_DIR rm -f * provided the options are supported on your system. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: bash prompt misbehaving - correction.

2009-06-30 Thread Bernd Eggink
%T)]...@\h:\w]\\$\[\033[0m\] " This works correctly with bash 4.0.24. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Memory leak in for loops

2009-04-30 Thread Bernd Eggink
; i < 15000; ++i )) do echo $i > /dev/null done instead. Consumes nearly no memory at all. Cheers, Bernd -- Bernd Eggink http://sudrala.de

Re: Crash in hashlib.c

2009-04-19 Thread Bernd Eggink
Chet Ramey schrieb: Bernd Eggink wrote: Version: GNU bash, Version 4.0.17(1)-release (i686-pc-linux-gnu) (plus newline-shellmeta patch). A script which uses, among other things, 3 associative arrays and a coprocess, crashes reproducibly with an allocation error: malloc: hashlib.c:306

Crash in hashlib.c

2009-04-17 Thread Bernd Eggink
unallocated block argument Abbruch... Program received signal SIGABRT, Aborted. 0xe424 in __kernel_vsyscall () Appended is a stack trace. Hope it helps. Regards, Bernd -- Bernd Eggink http://sudrala.de malloc: hashlib.c:306: assertion botched free: called with unallocated block argument

Re: Bug: 'case' in command substitution not handled correctly

2009-04-16 Thread Bernd Eggink
Chet Ramey schrieb: Bernd Eggink wrote: GNU bash, Version 4.0.17(1)-release (i686-pc-linux-gnu) The shell doesn't recognize the closing parenthesis of a command substitution if a 'case' command is included and 'esac' is preceded by newline. Example: x=$(case $a in (

Bug: 'case' in command substitution not handled correctly

2009-04-15 Thread Bernd Eggink
You can enter as many ')' as you like, the shell still wants another one. This variant works, however: x=$(case $a in (1) echo one;esac ) Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: feature-request: brief syntax for $(type -p somecommand)

2009-04-02 Thread Bernd Eggink
p) here: http://www.sudrala.de/en_d/shell-cmdexp.html Maybe it is of use for you, too. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: reference dir ../common in script

2009-03-06 Thread Bernd Eggink
em to like it and I can't figure it out. Thanks for any help, Duane You have a wrong logic. This script will mkdir if it exists. use [ ! -d "${CommonDir}" ] Or use mkdir -p $CommonDir Bernd -- Bernd Eggink http://sudrala.de

Re: Behaviour of cd changed?

2009-02-24 Thread Bernd Eggink
Chet Ramey schrieb: Bernd Eggink wrote: I'm still having problems with the cd builtin. In bash 3, the commands cd cd "" both changed to the user's home directory. In bash 4 (with patch "save-current-token" applied) cd "" does nothing. Bug or

Behaviour of cd changed?

2009-02-24 Thread Bernd Eggink
I'm still having problems with the cd builtin. In bash 3, the commands cd cd "" both changed to the user's home directory. In bash 4 (with patch "save-current-token" applied) cd "" does nothing. Bug or feature? Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Problem with function cd in bash 4.0

2009-02-24 Thread Bernd Eggink
Chet Ramey schrieb: Bernd Eggink wrote: I normally wrap the builtin cd into a function cd, which does some additional things and then calls the builtin. Example: function cd { local list=$(echo *.bui) # ... builtin cd "$1" } I have a PS1 like this:

Problem with function cd in bash 4.0

2009-02-23 Thread Bernd Eggink
. Is that a bug? I can get the intended behaviour by putting eval "PS1='$PS1'" at the end of the function, but that's a rather ugly workaround. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: echo $s{2,3}

2008-12-13 Thread Bernd Eggink
are set. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: =~ behaves differently in bash 3.2 and 3.0

2008-10-24 Thread Bernd Eggink
rue Don't know about 3.0.14, but it looks like it performed expansion on the regexp, while 3.2.39 leaves it unchanged. Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: implementing flow control in bash

2008-10-21 Thread Bernd Eggink
ant something like: for i in `find . -name \*gif`; do identify -format "$i %w" $i if [%w 570]; done > results.txt for i in $(find -name '*.gif') do w=$(identify -format %w $i) (( w > 570 )) && echo "$i $w" done Hope that helps, Bernd -- Bernd Eggink http://sudrala.de

Re: running source twice wont use arguments

2008-10-18 Thread Bernd Eggink
The value of this variable is not automatically reset if you start another getopts loop, you have to do it yourself: OPTIND=1 while getopts "ow:" opt do ... done Regards, Bernd -- Bernd Eggink http://sudrala.de

Re: Bash prints syntax error when command in $(...) contains case-esac

2008-09-30 Thread Bernd Eggink
e 3) with the last unpaired left paren (in $( ). Using (3) and (4) instead makes the example work. Unpaired parens are hideous anyway, IMHO. Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Expanding an undefined array

2008-09-24 Thread Bernd Eggink
' in the first example appears to be some kind of 'super-nothing'. Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: PATH value doesn't get updated

2008-05-18 Thread Bernd Eggink
Peter Volkov schrieb: Better way to check if shell is login is: $ shopt | grep login_shell login_shell on You don't even have to call an external program: [[ $(shopt -p login_shell) == *-s* ]] Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: Which Bash

2008-02-24 Thread Bernd Eggink
2.05b.0(1)-release? Looks like there are at least 2 versions on your system: Your login shell is probably bash-2.05b, while /opt/local/bin/bash (the latest version) is found via $PATH. Check your account data and PATH setting to verify it. Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http

Re: Bash 3.2.25 not expanding subscript...

2008-02-12 Thread Bernd Eggink
same name, but that doesn't matter) is unchanged. Try this instead: while read File do FileList[d]=$File (( d=d+1 )) done <<<"$(ls -1)" Greetings, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: capturing sub-expressions?

2008-01-29 Thread Bernd Eggink
Paul Jarc schrieb: Bernd Eggink <[EMAIL PROTECTED]> wrote: My impression is that the pattern lookup depends on whether or not a !' is involved. If the pattern does not contain a '!', the shell looks for matching substrings, from left to right. If it contains a '!

Re: capturing sub-expressions?

2008-01-29 Thread Bernd Eggink
ubstring matching the pattern "not a sequence of at least one digit" would have been 'a' (or maybe 'ab'), and the output would have been '12Xb34' (or '12X34'). IMHO (please correct me if I'm wrong) this contradicts the usual meaning of the '!' operator and makes it nearly useless - except in the simple "echo !(foo)" case you mentioned. Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: capturing sub-expressions?

2008-01-28 Thread Bernd Eggink
$x unchanged. I'm not sure whether this is a bug or I (we) miss something. Interestingly, ksh behaves the same way. Can anybody clarify this? Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: Exit application with two function calls

2008-01-27 Thread Bernd Eggink
asdf don't print The reason is that `check_file` is executed in a subshell, so 'exit' just leaves the subshell, not the script itself. The command substitution is unnecessary anyway, as the result (if any) will simply be $1 itself. Thus, if you replace the main part by

Re: Bash string substitution bug (?)

2008-01-11 Thread Bernd Eggink
Chet Ramey schrieb: Bernd Eggink wrote: prompt: CLUSTER='1 2'; echo ${CLUSTER/${HOSTNAME/.*}} output: -bash: ${HOSTNAME: bad substitution Apparently bash interprets this as ${parameter/pattern/string} where pattern = ${HOSTNAME. Looks like a bug; it wo

Re: Bash string substitution bug (?)

2008-01-11 Thread Bernd Eggink
t: -bash: ${HOSTNAME: bad substitution Apparently bash interprets this as ${parameter/pattern/string} where pattern = ${HOSTNAME. Looks like a bug; it works in ksh. As a workaround, you could use: H=${HOSTNAME/.*} echo ${CLUSTER/$H} Regards, Bernd -- Bernd Eggink [E

Re: Comparison failure

2008-01-10 Thread Bernd Eggink
ess than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers. Personally, I like the bash documentation because it is complete and concise. Greetings, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: regexp matching broken in bash-3.2.x?

2007-10-27 Thread Bernd Eggink
Pierre Gaston schrieb: On 10/27/07, Bernd Eggink <[EMAIL PROTECTED]> wrote: Pavel Gorshkov schrieb: Description: Regexp matching seems to be broken since 3.2.0. Repeat-By: The following used to work in bash-3.1: $ [[ test =~ 't.*t' ]]; echo $? 1 It w

Re: regexp matching broken in bash-3.2.x?

2007-10-27 Thread Bernd Eggink
ed. I, too, think it's a bug, as according to the docs, quote removal should be performed on the words between [[ and ]]. Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Pattern replacement fails if string contains multibyte characters

2007-09-28 Thread Bernd Eggink
(1)-release (i686-pc-linux-gnu) Without multibyte chars, replacement works as expected. I looks like a bug, or am I misssing something? Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Re: Help with script --

2007-08-28 Thread Bernd Eggink
t0nedef schrieb: echo "Please enter a network name" read ESSID if [ -n $ESSID ] You probably meant: if [ -z $ESSID ] then echo "unable to use a blank network name" exit $E_NOESSID fi Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://sudrala.de

Feature request: Escaping special characters in 'select' list

2007-06-27 Thread Bernd Eggink
t;^[[42maha^[[0m" one two three; do : ; done 1) aha 3) two 2) one 4) three #? (On a terminal, the first word has a green background). Regards, Bernd -- Bernd Eggink [EMAIL PROTECTED] http://monoped.de ___ Bug-bash mail

Pattern replacement inconsistency

2007-05-30 Thread Bernd Eggink
{x[*]//#/y} # output: a1 a2 a3 echo ${x[*]//#a/y} # output: a1 a2 a3 echo ${x[*]//a/y} # output: y1 y2 y3 -- Bernd Eggink [EMAIL PROTECTED] http://monoped.de ___ Bug-bash mailing list Bug-bash@gnu.org http://lists.gnu.org/mailman/listinfo/bug-bash