Re: how to workaroun 'nl' being added to input-line after 49 characters....

2011-02-14 Thread Greg Wooledge
On Sun, Feb 13, 2011 at 08:17:05PM -0700, Bob Proulx wrote: _CRed=$(tput setaf 1) #Red _CRST=$(tput sgr0) #Reset _CBLD=$(tput bold) #Bold _prompt_open= _prompt_close= _prompt= [[ $UID -eq 0 ]] { _prompt_open=$_CBLD$_CRed _prompt_close=$_CRST

Re: compat31

2011-02-15 Thread Greg Wooledge
On Mon, Feb 14, 2011 at 07:26:16PM -0600, Dennis Williamson wrote: The user is performing this from a shell prompt. I had him try [[ $BASH_VERSION =~ 4\.0 ]] echo yes || echo no which should output yes only if he's using Bash 4.0 *and* compat31 is on. Gah. Too much trickery and

Re: Bash 4.2 printf %()T seems to ignore TZ

2011-02-16 Thread Greg Wooledge
On Tue, Feb 15, 2011 at 09:49:16PM -0600, Dennis Williamson wrote: SECS=1275250155 export TZ=EST5EDT printf %()T\n $SECS printf %(%e-%b-%Y %T %Z)T\n $SECS # added %Z result: 15:09:15 30-May-2010 15:09:15 CDT I can't duplicate your problem on HP-UX 10.20: imadev:~$ s=1275250155;

Re: Inconsistence when checking if a pattern is quoted or not for `==' and `=~' in [[ ]]

2011-02-17 Thread Greg Wooledge
On Thu, Feb 17, 2011 at 10:56:21PM +0800, Clark J. Wang wrote: The point is: ``Any part of the pattern may be quoted to force it to be matched as a string.'' And backslash is one of bash's quoting chars. But in my examples, a pattern with `\' in it sometimes is considered to be quoted and

Re: Inconsistence when checking if a pattern is quoted or not for `==' and `=~' in [[ ]]

2011-02-17 Thread Greg Wooledge
On Thu, Feb 17, 2011 at 05:07:40PM +0200, Pierre Gaston wrote: On Thu, Feb 17, 2011 at 4:56 PM, Clark J. Wang dearv...@gmail.com wrote: The point is: ``Any part of the pattern may be quoted to force it to be matched as a string.'' And backslash is one of bash's quoting chars. aaah well

Re: Inconsistence when checking if a pattern is quoted or not for `==' and `=~' in [[ ]]

2011-02-18 Thread Greg Wooledge
On Thu, Feb 17, 2011 at 05:18:23PM -0500, Chet Ramey wrote: Maybe if the man page had read ...to force the quoted portion to be matched as a string this could have been avoided. I like this answer. Removing ambiguity (it could refer to the whole pattern or to the quoted portion) is always

Re: [bash 4.2] `declare -g' bug?

2011-02-18 Thread Greg Wooledge
On Fri, Feb 18, 2011 at 11:25:48AM +0800, Clark J. Wang wrote: A global var can always be declared out of a func (usually at the beginning of the script) so what's the main intention of introducing a new `-g' option? The main reason, as I understand it, is so that you can declare an

Re: Brace expansion inside of command substitution - broken or is it me?

2011-02-18 Thread Greg Wooledge
On Fri, Feb 18, 2011 at 10:32:13PM +0100, Peter Hofmann wrote: $ echo $(echo {1..3}) 1 2 3 Huh? Brace expansion is a funny thing. My belief at the moment -- I'm sure someone will correct me if I'm wrong -- is that because you've got everything quoted up, it's all seen as one word by the

Re: Brace expansion inside of command substitution - broken or is it me?

2011-02-18 Thread Greg Wooledge
On Fri, Feb 18, 2011 at 10:53:31PM +0100, Andreas Schwab wrote: Greg Wooledge wool...@eeg.ccf.org writes: On Fri, Feb 18, 2011 at 10:32:13PM +0100, Peter Hofmann wrote: $ echo $(echo {1..3}) 1 2 3 Huh? Brace expansion is a funny thing. My belief at the moment -- I'm sure

Re: set -e, but test return not honoured _conditionally_

2011-02-22 Thread Greg Wooledge
On Fri, Feb 18, 2011 at 04:36:06PM +0100, Steffen Daode Nurpmeso wrote: I am not a sophisticated shell programmer, but i really think this time it's a shell fault. You think *what* is the shell's fault? You may invoke the code snippet via 'script test1 test3' or so. #!/bin/sh

Re: no way to give 'select' a default value

2011-02-22 Thread Greg Wooledge
On Mon, Feb 21, 2011 at 04:05:34PM +0800, jida...@jidanni.org wrote: There is no way to give the 'select' command a default value, so all the user does is need to hit return. $ help select ... If the line is empty, WORDS and the prompt are redisplayed. `select' is extremely limited. If

Re: How to match pattern in bash?

2011-02-23 Thread Greg Wooledge
On Tue, Feb 22, 2011 at 08:03:39PM -0800, Micah Cowan wrote: Bash's special builtin [[ ]] syntax also provides both wildcards, and (much more powerful) extended regexes (roughly similar to Perl regexes; they're what egrep uses). Just for the record, ERE (Extended Regular Expressions), as used

Re: Problem with how to assign an array

2011-02-24 Thread Greg Wooledge
On Thu, Feb 24, 2011 at 02:55:13PM -0500, Steven W. Orr wrote: I have three arrays a1=(aaa bbb ccc ddd) a2=(qqq www eee rrr) a3=(fff ggg hhh) I then set a_all a_all=(${a1[*]} ${a2[*]} ${a3[*]} Missing ). Also, a far more serious problem, you used * when you should have used @.

Re: Problem with how to assign an array

2011-02-25 Thread Greg Wooledge
On Thu, Feb 24, 2011 at 06:59:02PM -0500, Steven W. Orr wrote: I intentionally used the star instead of the atsign because I'm taking advantage of the fact that these array elements all have no whitespace. So, after the assignment to a_all, the value of a[0] is equal to the single string

Re: bash tab variable expansion question?

2011-02-25 Thread Greg Wooledge
On Fri, Feb 25, 2011 at 09:46:58AM +, Davide Brini wrote: Maybe, but then it shouldn't escape the $ either, as the OP is reporting for 4.2 (I don't have a 4.2 handy to test it). I actually noticed this quite recently, but didn't think to bring it up. I had just typed some cd command, and

Re: Bash-4.2 Official Patch 5

2011-03-01 Thread Greg Wooledge
On Tue, Mar 01, 2011 at 10:20:29AM -0500, Chet Ramey wrote: *** ../bash-4.2-patched/variables.c 2011-02-25 12:07:41.0 -0500 --- variables.c 2011-03-01 10:13:04.0 -0500 *** *** 3661,3665 v = find_variable (name); ! if (exported_p (v))

Re: How to safely pipe output to tee?

2011-03-07 Thread Greg Wooledge
On Mon, Mar 07, 2011 at 03:22:26PM -0500, Steven W. Orr wrote: foo='sleep 100 - 2- ' Sleep for 100 seconds and then close channel 1 and channel 2. No. Redirections are done first.

Re: variable name and its' value are the same characters causes recursion error

2011-03-10 Thread Greg Wooledge
On Thu, Mar 10, 2011 at 10:18:26AM +0800, Clark J. Wang wrote: Actually I don't like the recursion here. Does POSIX require that? For example: unset a; declare a=a; [[ a -lt 3 ]]; echo $? bash: [[: a: expression recursion level exceeded (error token is a) 1 POSIX doesn't even have a

Re: case modification won't work with pattern

2011-03-10 Thread Greg Wooledge
On Thu, Mar 10, 2011 at 10:22:12AM +0800, Jerry Wang wrote: var=abcabc echo var: ${var} echo replace the leading \ab\ to uppercase: ${var^ab} # expect to get ABcabc ? The documentation is a bit terse, admittedly. What the ^ operator does is compare the *first character* of

Re: Hightlighting in bash

2011-03-10 Thread Greg Wooledge
On Thu, Mar 10, 2011 at 11:42:25AM -0800, Philip Prindeville wrote: My request is simple. HAH! Lies Using termcap/ncurses info (which you need anyway for the readline stuff), it would be nice to have the option of running commands in a pseudo-tty and then bracketing the output from

Re: Hightlighting in bash

2011-03-10 Thread Greg Wooledge
On Thu, Mar 10, 2011 at 12:49:27PM -0800, Micah Cowan wrote: When both stdout and stderr are the same tty, how do you expect to use this method to detect which text should be hilighted and which shouldn't? Arrange so that's not the case. Most likely by running something like magicthing

Re: Infinite loop in globbing

2011-03-14 Thread Greg Wooledge
On Mon, Mar 14, 2011 at 10:00:14AM +0100, Roman Rakus wrote: $ locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8

Re: Problem with open and rm

2011-03-16 Thread Greg Wooledge
On Wed, Mar 16, 2011 at 10:54:15AM +, Barrie Stott wrote: The script that follows is a cut down version of one that came from elsewhere. #!/bin/bash cp /tmp/x.html /tmp/$$.html ls /tmp/$$.html [ $DISPLAY ] open /tmp/$$.html ls /tmp/$$.html rm -f /tmp/$$.html If I comment out the

Re: configure fails with gcc 4.6.0 LTO

2011-03-21 Thread Greg Wooledge
On Sat, Mar 19, 2011 at 09:52:05PM +, Zeev Tarantov wrote: configure:3122: checking for C compiler default output file name configure:3144: x86_64-pc-linux-gnu-gcc -g -O2 -flto -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

Re: BASH_SUBSHELL documentation misleading

2011-03-24 Thread Greg Wooledge
On Thu, Mar 24, 2011 at 02:33:19PM +, Marc Herbert wrote: I would also like to see this example in the documentation: $ ( echo sub-$BASH_SUBSHELL ); echo main-$BASH_SUBSHELL sub-1 main-0 Overkill. Most of the other features in the manual do not have such examples, and if we added

Re: BASH_SUBSHELL documentation misleading

2011-03-24 Thread Greg Wooledge
On Thu, Mar 24, 2011 at 06:07:33PM +, Marc Herbert wrote: Not every feature is complicated enough that it requires special documentation care and that it raises a discussion here. BASH_SUBSHELL isn't complicated at all. It's just documented in a confusing way. It doesn't require an

Re: bizarre trap behavior while reading a file

2011-03-28 Thread Greg Wooledge
On Fri, Mar 25, 2011 at 02:25:35PM -0700, tytus64 wrote: while read line do line_num=`expr $line_num + 1` echo $line_num: $line ./out.log done $log_file Although it's not directly related to your question, I feel obliged to point out that you can increment a variable without

Re: bizarre trap behavior while reading a file

2011-03-28 Thread Greg Wooledge
On Mon, Mar 28, 2011 at 06:59:23AM -0700, tytus64 wrote: Interesting... I used kill -HUP pid instead of killall -HUP prog_name and it works without interrupting the first loop. I also noticed 2 processes running when the first loop is iterating but only 1 when the second loop is iterating:

Re: RFE: make [[ compatible with [ 'Option'?

2011-03-28 Thread Greg Wooledge
On Mon, Mar 28, 2011 at 10:53:21AM -0700, Linda Walsh wrote: if [ ! -e $d/S??sshd ]; then echo sshd not enabled; fi That will fail quite colorfully if the glob matches multiple files. (Also, $d should be quoted.) On IRC we recommend enabling nullglob, pulling the results of the glob into an

Re: bizarre trap behavior while reading a file

2011-03-29 Thread Greg Wooledge
On Tue, Mar 29, 2011 at 08:02:17AM -0400, Steven W. Orr wrote: Is there a difference between while read line file do stuff done vs while read line do stuff done file Yes. It's a huge difference. In the first one, the file is re-opened by read every time through the

Re: When double quote is considered when not?

2011-03-30 Thread Greg Wooledge
On Wed, Mar 30, 2011 at 02:43:58PM +0430, ali hagigat wrote: -- var1=word1 word2 echo $var1 if (test -z \$var1\) then echo first else echo second fi Problems in this script: * Unquoted $var1 on line 2. This means that instead of passing the actual

Re: Why is command substitution happening?

2011-04-12 Thread Greg Wooledge
On Mon, Apr 11, 2011 at 12:23:15PM -0600, Bill Gradwohl wrote: -BEGIN PGP SIGNED MESSAGE- I have a tiny script to prune empty directories from a structure. The essential line is as follows: tree --noreport -dfi ${1} | tac | sed 's//\\/g;s/^/rmdir - --ignore-fail-on-non-empty

Re: Question about arithmetic logic.

2011-04-18 Thread Greg Wooledge
On Mon, Apr 18, 2011 at 10:30:35AM -0400, Steven W. Orr wrote: ss=1 (( ss )) echo $? # Also says 1. Should this be 0 because it should be the # success result same as (( ss != 0 )) That's not what I get: imadev:~$ unset ss; ss=0; ((ss)); echo $? 1 imadev:~$

Re: Question about arithmetic logic.

2011-04-18 Thread Greg Wooledge
On Mon, Apr 18, 2011 at 10:57:00AM -0400, Steven W. Orr wrote: I get the same result as you when I do it your way. But if I add the typeset, I still get the same result: 515 unset ss; typeset -i ss=1; ((ss)); echo $? 0 516 unset ss; typeset -i ss=0; ((ss)); echo $? 1 Interesting. So

Re: awk or sed

2011-04-25 Thread Greg Wooledge
On Sat, Apr 23, 2011 at 11:07:06AM +0430, ali hagigat wrote: I have a makefile and I want to print each word of the variable, .VARIABLES on a separate line. It seems that the previous simple solution of Mr. Johnson here does not work, means: printf %s\n $var make(1) is a separate program

Re: Is this an IFS bug in getopts?

2011-04-26 Thread Greg Wooledge
On Tue, Apr 26, 2011 at 12:41:49PM -0400, Steven W. Orr wrote: It turns out that when I called getopts, I had set IFS='-'. I assume you mean when I called die. die() { typeset opt typeset opt_s=1 typeset opt_i=0 typeset err_opts= OPTIND=1 while getopts ':is:'

Re: eval

2011-05-04 Thread Greg Wooledge
On Tue, May 03, 2011 at 09:41:28PM -0500, Jonathan Nieder wrote: Rafael Fernandez wrote: set -- a b c d e f g h i j k l m n o p q r s t u v w x y z i=1 eval echo '$'$i # outputs an expected 'a' I didn't see the original question yet, but it looks like you're

Re: Matching regular expression with Ctrl-A in the middle

2011-05-05 Thread Greg Wooledge
On Wed, May 04, 2011 at 10:23:20AM -0500, Shawn Bohrer wrote: -bash-4.1$ [[ helloworld =~ oworld$ ]] echo match -bash-4.1$ Confirmed here (HP-UX 10.20), even using the approved stuff the RE into a variable workaround that fixes most =~ problems: imadev:~$ bash-4.1.7 imadev:~$

Re: Yet another quoting question

2011-05-06 Thread Greg Wooledge
On Fri, May 06, 2011 at 11:02:32AM -0400, Steven W. Orr wrote: I wanted to write a routine to print out an array. It just takes the name of the array as an argument. Flee in terror. Do not look back. Oh, wait, you want a useful answer? Switch to ksh93 and use nameref. You CANNOT do this

Re: Yet another quoting question

2011-05-06 Thread Greg Wooledge
On Fri, May 06, 2011 at 11:50:34AM -0400, Chet Ramey wrote: Eric suggested %q, and that works to a certain degree, but you can also use printf '%s ' ${vals[@]} ; echo and get the double-quoting you want. Fails horribly if the array elements contain double quotes of their own.

Re: Reading mysql data stream into array

2011-05-06 Thread Greg Wooledge
On Fri, May 06, 2011 at 06:22:25PM +0200, Dirk wrote: I was fooled by echo $SHELL returning /bin/bash, but when I manually call /bin/bash before running the above command (it is not a script yet), it works. What the heck is going on here ... (!xmpf) The $SHELL variable does not

Re: accents

2011-05-10 Thread Greg Wooledge
On Tue, May 10, 2011 at 04:47:29AM +0200, Thomas De Contes wrote: tDeContes-fixe:~ thomas$ echo $PS1 + echo '\h:\W \u\$ ' \h:\W \u\$ if i do not PS1=# $PS1 then i don't have the problem described in 1 I am not able to reproduce this in my environment. I'm using Debian 6.0 on i386, I

Re: echo foo a b does not error

2011-05-12 Thread Greg Wooledge
On Thu, May 12, 2011 at 03:13:51PM +0300, Petteri Räty wrote: Repeat-By: betelgeuse@pena ~/test $ echo foo a b This one is not an error; it simply does not mean what you think it means. The following commands are all equivalent: echo foo a b echo a foo b a echo foo b echo foo b a

Re: builtin read stops at '\0'

2011-05-19 Thread Greg Wooledge
On Wed, May 18, 2011 at 02:10:39PM +0200, Rafaël Fourquet wrote: If a line containing the '\0' is read into a variable, the content of this variable does not contain the part after the '\0' character. Repeat-By: echo -e 'a\0b' | (read f; echo $f) The output

Re: builtin read stops at '\0'

2011-05-19 Thread Greg Wooledge
On Thu, May 19, 2011 at 03:23:55PM +0200, Rafaël Fourquet wrote: I have a program which outputs groups of filenames. Each group is separated by a newline, and within each group, each name is separated by '\0'. That seems backwards somehow... the stronger delimiter (NUL) is used in the inner

Re: builtin read stops at '\0'

2011-05-19 Thread Greg Wooledge
On Thu, May 19, 2011 at 04:30:40PM +0200, Rafaël Fourquet wrote: Do you mean, in your example, that e.g. ... do mapfile -t files $group ; ls -1 ${files[@]}; done ... is better than: ... do xargs -d '\n' ls -1 $group; done ... imadev:~$ group=$'foo\nbar\nhi mom\n' imadev:~$ xargs -d '\n'

Re: BUG? RFE? printf lacking unicode support in multiple areas

2011-05-20 Thread Greg Wooledge
On Fri, May 20, 2011 at 12:31:31AM -0700, Linda Walsh wrote: 1) use of of the \u and \U escape sequences in the format string (16 and 32 bit Unicode values). This isn't even a sentence. What bash command did you execute, and what did it do, and what did you expect it to do? In

Re: BUG? RFE? printf lacking unicode support in multiple areas

2011-05-20 Thread Greg Wooledge
On Fri, May 20, 2011 at 03:29:59PM +0200, Ralf Goertz wrote: In bash 4.2, on a Debian 6.0 box with a UTF-8 locale, printf '\u203c\n' I am not Linda but in my setting (4.1.10(1)-release) under linux 64bit I have $ printf \u203c\n \u203c It it a bash 4.2 feature; it does not work in bash

Re: BUG? RFE? printf lacking unicode support in multiple areas

2011-05-23 Thread Greg Wooledge
On Fri, May 20, 2011 at 03:03:25PM -0700, Linda Walsh wrote: %lc uses wide chars 'wchar_t or wint_t'. These are 16 bits on Wincygwin and 32 on with glib. There is no such thing as a wchar_t or a wint_t in Bash. There is no such thing as a 16-bit or 32-bit integer type, neither big-endian

Re: Stumped on a question of scoping and unset.

2011-05-26 Thread Greg Wooledge
On Wed, May 25, 2011 at 05:15:28PM -0400, Steven W. Orr wrote: In addition, I wrote (what I thought was pretty clever) a function called glob_array: glob_array() { [[ snip ]] while (( $# )) do arrayname=$1 pattern=$2 aval=( $pattern ) Looks like what

Re: last argument expansion has different output using the sh interpreter

2011-05-27 Thread Greg Wooledge
On Fri, May 27, 2011 at 12:35:12PM -0700, Jacoby Hickerson wrote: When executing a test script using the #!/bin/sh interpreter line the shell expansion for the last argument ${!#} is blank, Good. And now you know why you use a proper #!/bin/bash shebang when you use bash extensions in

Re: last argument expansion has different output using the sh interpreter

2011-05-27 Thread Greg Wooledge
On Fri, May 27, 2011 at 01:35:50PM -0700, Jacoby Hickerson wrote: Although, I am curious, is this is a matter of sh being continually updated to exclude all bash extensions Eh? POSIX is defined by a group of people and published. Here's the current edition:

Re: documentation bug re character range expressions

2011-06-03 Thread Greg Wooledge
On Fri, Jun 03, 2011 at 12:06:32AM -0700, Marcel (Felix) Giannelia wrote: Is it really a programmer mistake, though, to assume that [A-Z] is only capital letters? Yes, it is. You should be using [[:upper:]], or you should be setting LC_COLLATE=C if you insist on using [A-Z].

Re: documentation bug re character range expressions

2011-06-03 Thread Greg Wooledge
Oh, look, there's more! On Fri, Jun 03, 2011 at 12:06:32AM -0700, Marcel (Felix) Giannelia wrote: [[:alpha:]] is too difficult to type to make it useful for the kind of quick pattern-matching that character ranges are used for on the interactive shell. Try it. Open-bracket, colon is an

Re: documentation bug re character range expressions

2011-06-03 Thread Greg Wooledge
On Fri, Jun 03, 2011 at 09:15:55AM -0700, Marcel (Felix) Giannelia wrote: Alright -- assuming that for the moment, how does one specify [ABCDEFGHIJKL] using [[:upper:]]? This is something that I haven't seen documented, and I'm genuinely curious. You can't. Either write out [ABCDEFGHIJKL]

Re: documentation bug re character range expressions

2011-06-03 Thread Greg Wooledge
On Fri, Jun 03, 2011 at 09:12:07AM -0700, Marcel (Felix) Giannelia wrote: And yours looks broken -- how does echo Hello World | tr A-Z a-z result in a bunch of non-ASCII characters? I explain it in a bit on http://mywiki.wooledge.org/locale In a bit more depth: in ASCII, the characters A-Z

Re: printf treats arguments of %c not as expected

2011-06-23 Thread Greg Wooledge
2011/6/23 Jan Schampera jan.schamp...@web.de: However, Mr. Wang may want to read one of Greg's brilliant FAQ entries [1]. [1] http://mywiki.wooledge.org/BashFAQ/071 On Thu, Jun 23, 2011 at 04:00:35PM +0800, Yunfeng Wang wrote: Thanks Jan, Greg's solution is great! Just for the record, I

Re: Calling Bash with /S

2011-06-23 Thread Greg Wooledge
On Wed, Jun 22, 2011 at 09:59:45AM -0700, sweinberger wrote: /bin/bash /S /c ... MS-DOS 3.30? Or a modified version of bash? Or both? In Make File: @ls -l ./SomeDir/* Bash Command /bin/bash /S /c ls -l ./SomeDir/* The /S from what I see enables regular expression processing in the

Re: weird behavior of set -e

2011-06-24 Thread Greg Wooledge
http://mywiki.wooledge.org/BashFAQ/105 -- Why doesn't set -e (set -o errexit) do what I expected?

Re: 4.2 error: processing command substitution within arithmetic operation

2011-06-24 Thread Greg Wooledge
On Fri, Jun 24, 2011 at 06:18:08PM +0100, Rui Santos wrote: Try this script: #!/bin/bash declare -ax array array[$(( $( echo -n 1001 ) - 1001 ))]=1 this will issue an error: line 6: 1001: command not found imadev:~$ unset array imadev:~$ array[$(( $( echo -n 1001 ) - 1001 ))]=1 imadev:~$

Re: Negative indexes in ${arr[@]:off:length}

2011-06-27 Thread Greg Wooledge
On Sat, Jun 25, 2011 at 05:35:24PM +0200, lhun...@lyndir.com wrote: arr=(a b c); echo ${arr[-1]} In line with that, I'd like to propose extending that functionality to other operations that address array elements: echo ${arr[@]:0:-1} # Expected: c echo ${arr[@]:1:-2} #

Re: Negative indexes in ${arr[@]:off:length}

2011-06-29 Thread Greg Wooledge
On Wed, Jun 29, 2011 at 01:42:06PM +0200, Maarten Billemont wrote: If you expand ${arr[@]:1:2}, you get the following: values: [ a | b | c ] indexes: 0 1 2 3 expand: [ 1 2 ] = b c ^ start from 1 ^ length 2 I propose we let a negative length

Re: Negative indexes in ${arr[@]:off:length}

2011-06-30 Thread Greg Wooledge
On Wed, Jun 29, 2011 at 06:41:25PM +0200, Maarten Billemont wrote: This is where preceding the element with the index comes in handy: We start with the index 1, which lays between element 0 and element 1. ... I have a feeling you're taking this definition from some other language. Python

Re: Negative indexes in ${arr[@]:off:length}

2011-06-30 Thread Greg Wooledge
On Wed, Jun 29, 2011 at 06:41:25PM +0200, Maarten Billemont wrote: For those to whom a cursor between elements seems confusing: think of your prompt's cursor and imagine an element is a single character. No wonder this makes no sense to me. Have you actually looked at the cursor in a

Re: Yet Another test option

2011-07-05 Thread Greg Wooledge
On Sun, Jul 03, 2011 at 11:41:02AM -0700, Bruce Korb wrote: P.S. this check is really for any version below 2.6.27: - case $LINUXRELEASE in - # ext4 was in 2.6.22-2.6.26 but not stable enough to use - 2.6.2[0-9]*) enable_ext4='no' ;; - *) . ;; and might have been

Re: Coproc usage ... not understanding

2011-08-10 Thread Greg Wooledge
On Tue, Aug 09, 2011 at 05:47:09PM -0700, Linda Walsh wrote: Bob Proulx wrote: This may be a good point to mention this reference: http://www.pixelbeat.org/programming/stdio_buffering/ Does it only work with gnu programs? I.e. how would they know to not buffer Sounds like

Re: Coproc usage ... not understanding

2011-08-10 Thread Greg Wooledge
On Wed, Aug 10, 2011 at 10:07:20AM -0600, Bob Proulx wrote: The unbuffer expect script sets up a tty around the called program so that instead of a pipe the program detects a tty. The stdbuf utility works by setting up an LD_PRELOAD library libstdbuf.so that replaces the libc calls and

Re: test -nt not sane

2011-08-10 Thread Greg Wooledge
On Wed, Aug 10, 2011 at 11:53:52AM -0700, Curtis Doty wrote: touch -hr directory symlink touch: illegal option -- h Hmm, what is that? Let's check a GNU/Linux box: -h, --no-dereference affect each symbolic link instead of any referenced file (useful only

Re: test -nt not sane

2011-08-10 Thread Greg Wooledge
On Wed, Aug 10, 2011 at 03:25:49PM -0400, Chet Ramey wrote: The man page says: file1 -nt file2 True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not. Ah. The help test page is shorter: FILE1 -nt FILE2 True if file1

Re: Warning (HTML included to show prog shipped w/syntax highlighting).

2011-08-11 Thread Greg Wooledge
On Wed, Aug 10, 2011 at 03:23:47PM -0700, Linda W wrote: 1 #!/bin/bash 2 30 31 # trace control for subs 32 declare -ix Allow_Trace=$((( 33 _D_LowLevel | 34 _D_Provides | 35 _D_ 36 ))) I

Re: Re: Inline `ifdef style` debugging

2011-08-11 Thread Greg Wooledge
On Thu, Aug 11, 2011 at 12:23:00AM -0700, pjodrr wrote: they call it collapsing functions: http://wiki.bash-hackers.org/howto/collapsing_functions The first time you run chatter(), the function redefines itself based on the value of verbose. Thereafter chatter doesn't check $verbose anymore, it

Re: Re: Inline `ifdef style` debugging

2011-08-11 Thread Greg Wooledge
On Thu, Aug 11, 2011 at 12:38:17PM -0800, Roger wrote: OK. Now I see the collapsing, and it seems more like a hidden collapse rather then an immediately apparent collapse from an initial stance after reading/tracing. When tracing this function, I was thinking the function would be read each

set -e yet again (Re: saving bash....)

2011-08-12 Thread Greg Wooledge
On Thu, Aug 11, 2011 at 11:56:10PM -0700, Linda Walsh wrote: **Exception** declare -i a a=0 -- As a is declared to be an integer, it has the results evaluated at assignment time. a=0 is an integer expression that doesn't set $?=1 Neither should: ((a=0)) a=0 is an assignment.

Re: set -e yet again (Re: saving bash....)

2011-08-12 Thread Greg Wooledge
On Fri, Aug 12, 2011 at 08:18:42AM -0700, Linda Walsh wrote: If I write a==0 on the bash command line, it will generate an error. a=0 does not. 'Bash' knows the difference between an assignment and a equality test in math. imadev:~$ ((a==0)) imadev:~$ ((a=0)) imadev:~$ a==0 imadev:~$

Re: set -e yet again (Re: saving bash....)

2011-08-12 Thread Greg Wooledge
On Fri, Aug 12, 2011 at 12:19:59PM -0700, Linda Walsh wrote: Under -e, it would fail on the 'let' statement This is one of the cases I mention on http://mywiki.wooledge.org/BashFAQ/105 -e -- in a WELL DESIGNED PROG***, where errors are caught, shouldn't cause a otherwise working program

Re: Syntax Question...

2011-08-15 Thread Greg Wooledge
On Mon, Aug 15, 2011 at 12:45:58AM -0700, Linda Walsh wrote: #!/bin/bash -exu alias sub=function alias unless='if !' Aliases don't even *work* in scripts. typeset -xr sub unless declare -a SAVE_ARGS=( $@ ) typeset -xr snapdir='snapdir' # in shell: white is black and black is white:

Re: Syntax Question...

2011-08-16 Thread Greg Wooledge
On Mon, Aug 15, 2011 at 08:19:01PM -0700, Linda Walsh wrote: ` Dennis Williamson wrote: As has been said before, don't use bash -e. Why don't you convince Chet to remove it then? He can't, because people like you keep using it. Also, it's probably mandated by POSIX. I can't be bothered

Re: Syntax Question...

2011-08-17 Thread Greg Wooledge
On Tue, Aug 16, 2011 at 03:41:19PM -0700, Linda Walsh wrote: Ken Irving wrote: Maybe this? today_snaps=( ${snap_prefix} ) but as you mention, that will put them into an arraysorry imprecise terminology list for me is some number of objects in a string separated by some

Re: Syntax Question...

2011-08-17 Thread Greg Wooledge
On Tue, Aug 16, 2011 at 02:11:43PM -0700, Linda Walsh wrote: 2) His knowledge base about bash seems to be dated or lacking. His page on indirect assignment skips using arith expressions and skipped one line assignments for assigning to indirect vars using the It's a wiki, you know. It can

Re: UTF-8 format not supporting by Bourne again shell

2011-08-17 Thread Greg Wooledge
On Wed, Aug 17, 2011 at 10:54:02AM +, Kiran Kotla wrote: prog=snmpd start() { echo -n $Starting $prog: } value in the $prog displaying properly,bur the Starting message is scrambled. Bourne-Again shell format. The $... quoting is for localization (natural language

Re: conditional aliases are broken

2011-08-18 Thread Greg Wooledge
On Wed, Aug 17, 2011 at 08:46:34PM -0700, Linda Walsh wrote: how do you declare a variable for storage in the context of the caller? (using a function)... ??? The *caller* declares it. I found it very troublesome inside a function, to store a value into a local variable in the caller.

Re: Syntax Question...

2011-08-18 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 06:02:14AM -0700, Linda Walsh wrote: The shopt -s expand_aliases feature has been in bash since I first encountered it in ~1999. Fine. You know more bash bad practices than I do. You win. b=one two three read a $b echo $a one two three The word following

Re: conditional aliases are broken

2011-08-18 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 08:03:41AM -0700, Linda Walsh wrote: 4.2 introduce a new -g to declare a global variable inside a function. Which doesn't say what it would do in situations like the above. Then let's test: imadev:~$ echo $BASH_VERSION 4.2.10(7)-release imadev:~$ unset a b;

Re: Syntax Question...

2011-08-18 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 09:26:42AM -0700, Linda Walsh wrote: It's like -e was very using in bash 3.0-4.0, but you didn't know it so thought it worthless. I certainly knew about -e. It was bad back then, too. It's arguably worse now, because there are even more variants in implementation than

Re: Is this a bug in [[ -f ]]?

2011-08-18 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 12:35:37PM -0400, Steven W. Orr wrote: lrwxrwxrwx. 1 sorr fc5 Aug 18 08:48 err - errio -rw-rw-r--. 1 sorr fc 3816 Aug 18 08:48 errio *836 [[ -f err ]] 837 echo $? # BAD answer 0 Sounds like you want this: http://mywiki.wooledge.org/BashFAQ/097 - How do

Re: Syntax Question...

2011-08-18 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 02:42:03PM -0400, Chet Ramey wrote: The expansions are the default set as described in the quoted paragraph, without pathname expansion and, since the result is passed to the command as a single string, word splitting. I think the confusion arises over the precise

Re: YAQAGV (Yet Another Question About Global Variables)

2011-08-23 Thread Greg Wooledge
On Tue, Aug 23, 2011 at 09:42:21AM -0400, Steven W. Orr wrote: Since require is a function, any variables that are declared in a required module which declare global variables using typeset then become local variables to the require function. Then after the modules are loaded, the variables

Re: accents

2011-08-25 Thread Greg Wooledge
On Thu, Aug 25, 2011 at 03:09:04PM +0200, Thomas De Contes wrote: Well, libc is a part of linux, isn't it ? libc is the generic name for an implementation of the library of functions required by various standards, including ISO/ANSI C, POSIX, and so on. It's usually named libc* and located in

Re: Special parameter $_ expands to a relative path

2011-09-01 Thread Greg Wooledge
On Thu, Sep 01, 2011 at 01:15:34AM -0800, Roger wrote: MAILPATH A colon-separated list of file names to be checked for mail. The message to be printed when mail arrives in a particular file may be specified by separating the file name from the message with a

Re: Append history from each shell upon exiting GNU Screen

2011-09-12 Thread Greg Wooledge
On Sun, Sep 11, 2011 at 11:23:48PM -0800, Roger wrote: When using GNU Screen (or other terminal multiplexer), I noticed the terminal multiplexer never gives each bash shell opened, a chance to write the history file on exit. The usual result after an initial install for several months, the

Re: multi-dimensional arrays

2011-09-19 Thread Greg Wooledge
On Sat, Sep 17, 2011 at 08:53:32PM -0400, Chet Ramey wrote: On 9/17/11 10:26 AM, Gerard Seibert wrote: Just out of curiosity, are there any plans to make multi-dimensional array variables available in future versions of Bash? I would find it extremely useful. I don't have any current

Re: Purge History of rm commands

2011-09-19 Thread Greg Wooledge
On Sun, Sep 18, 2011 at 10:11:17PM -0800, Roger wrote: On Mon, Sep 19, 2011 at 01:37:22AM -0400, Mike Frysinger wrote: On Monday, September 19, 2011 01:18:02 Roger wrote: I'm stumped on this as my history is in the format of: $ tail ~/.bash_history #1316296633 man bash #1316296664

Re: exec vs. source spawning piped commands

2011-09-22 Thread Greg Wooledge
On Wed, Sep 21, 2011 at 01:09:32PM -0400, Pete Nelson wrote: I'm confused about what exec is doing in this case. Sample script t: #!/bin/bash echo $0 pid: $$ ppid: $PPID args: $* 12 if [ -z $1 ]; then exec $0 first | $0 second echo should not reach here fi It does nothing. The $0

Re: How to match regex in bash? (any character)

2011-09-27 Thread Greg Wooledge
On Mon, Sep 26, 2011 at 07:06:30PM -0800, Roger wrote: Some good reading I found is under the Bash Manual Page section Parameter Expansion. From here, to learn more about regex/regexpr as the Bash Manual is quite brief on regex, use the following manual pages: perlretut - Gives a good

Re: How to match regex in bash? (any character)

2011-09-29 Thread Greg Wooledge
On Wed, Sep 28, 2011 at 12:43:01PM -0800, Roger wrote: Seems I used 'man regex' as well here. AKA regex(3). But I did realize this a few weeks ago; the real regex description being 'man 7 regex'. The Bash Manual Page denotes only regex(3). You're relatively fortunate that it's *that* easy to

Re: How to match regex in bash? (any character)

2011-09-29 Thread Greg Wooledge
On Thu, Sep 29, 2011 at 10:59:19AM -0500, Peng Yu wrote: We all have discovered that regex(3) is not consistent across all the platform. Why you say it is portable? The three systems I mentioned earlier today all have regex(3). Which system have you found, which doesn't have it? As I

Re: How to match regex in bash? (any character)

2011-09-29 Thread Greg Wooledge
On Thu, Sep 29, 2011 at 11:18:57AM -0500, Peng Yu wrote: Also, regex(3) does not mention the difference between $x =~ .txt and $x=~ .txt. I think that the difference should be addressed in man bash. It already is. An additional binary operator, =~, is available, with the

Re: Syntax Question...

2011-10-03 Thread Greg Wooledge
On Thu, Aug 18, 2011 at 11:10:17AM +0100, Stephane CHAZELAS wrote: Please read BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006 no force in the universe can put NUL bytes into shell strings usefully No, zsh supports NUL bytes in its strings happily. It's even in the default $IFS. Where

Re: Syntax Question...

2011-10-03 Thread Greg Wooledge
On Mon, Oct 03, 2011 at 12:56:43PM +, Stephane CHAZELAS wrote: If zsh is not compatible with any other shell, then bash isn't either. What do you mean? http://zsh.sourceforge.net/FAQ/zshfaq02.html#l10 because of all the options it is not safe to assume a general zsh run by a user will

Re: reverse video in PS1 breaks command line editing

2011-10-04 Thread Greg Wooledge
On Mon, Oct 03, 2011 at 02:20:26AM -0400, d...@cs.cmu.edu wrote: PS1=\e[7m\h:\w\e[0m You forgot to put \[ ... \] around the non-cursor-moving escape sequences.

<    1   2   3   4   5   6   7   8   9   10   >