Re: ionice bash pid in bash_profile Fails

2010-11-22 Thread Greg Wooledge
On Mon, Nov 22, 2010 at 07:41:48AM -0900, Roger wrote: > On Mon, Nov 22, 2010 at 08:39:49AM -0500, Greg Wooledge wrote: > >> ionice -c 2 -n 0 -p `pidof bash` > >If you want the PID of the current shell process, use $$ instead. > > Here's the error I get when loggin

Re: ionice bash pid in bash_profile Fails

2010-11-22 Thread Greg Wooledge
On Mon, Nov 22, 2010 at 12:44:54PM -0900, Roger wrote: > ionice -c 2 -n 0 -p `echo $$` You don't need echo or `` here. ionice -c 2 -n 0 -p $$

Re: IFS=':' set -- aa:bb:cc:dd # Fails to set "$@"

2010-12-01 Thread Greg Wooledge
On Wed, Dec 01, 2010 at 08:14:49AM -0500, ste...@syslang.net wrote: > IFS=':' set -- aa:bb:cc:dd > Instead, I have to say something like: > oldIFS="$IFS" > IFS=':' > set -- aa:bb:cc:dd > IFS="$oldIFS" Neither one of these sets $1 to aa, $2 to bb and so on. The

Re: Clear Screen

2010-12-01 Thread Greg Wooledge
On Wed, Dec 01, 2010 at 02:04:51PM -0700, Bob Proulx wrote: > If that doesn't do what you want then I don't think the functionality > you request exists. That's probably technically true. But on the other hand, I can see where his question is coming from. If you're on an rxvt or something, with

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

2010-12-02 Thread Greg Wooledge
On Thu, Dec 02, 2010 at 07:04:57PM +0800, 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 The output from the first command in the pipeline does not end with a newline. Therefore,

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

2010-12-02 Thread Greg Wooledge
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/s

Re: argument precedence, output redirection

2010-12-03 Thread Greg Wooledge
On Fri, Dec 03, 2010 at 06:16:06PM +0330, Payam Poursaied wrote: > What is the difference between: > ls -R /etc/ 2>&1 1>/dev/null > and > ls -R /etc/ 1>/dev/null 2>&1 http://mywiki.wooledge.org/BashFAQ/055 In a sentence, redirections are done in order, from left to right.

Re: comparison inside [[]] is not numeric comparison?

2010-12-09 Thread Greg Wooledge
On Fri, Nov 19, 2010 at 04:45:15PM -0800, john.ruckstuhl wrote: > In bash, a comparison inside "[["/"]]" is lexicographic not numeric? Correct. Assuming you use the string-comparison operators (> and <) rather than the integer-comparison operators (-gt, -lt, etc.). > $ if [[ 1000 > 200 ]]; then

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Greg Wooledge
On Fri, Dec 10, 2010 at 10:25:02AM +0100, Diggory Hardy wrote: > Uh. Then over time it is legitimate to have a script recursively call itself > a few thousand times with each instance still in memory? No. > The potential to grind the system to a complete halt is pretty serious > though. Perhaps t

Re: bash 'let' can give error

2010-12-10 Thread Greg Wooledge
On Thu, Dec 09, 2010 at 05:52:49PM +, Dominic Raferd wrote: > Why does this happen? Is it 'by design'? It makes arithmetic with bash > let very dangerous because it can throw unexpected errors (and break > scripts running with set -e). http://mywiki.wooledge.org/BashFAQ/105 -- Why doesn't s

Re: Recursively calling a bash script goes undetected and eats all system memory

2010-12-10 Thread Greg Wooledge
On Fri, Dec 10, 2010 at 03:23:46PM +0100, Diggory Hardy wrote: > What if bash were only to allow scripts to call themselves with exec? You can't prevent programmers from writing horrible code. At some point, it isn't worth the effort even to try.

Re: cd with multiple arguments?

2010-12-17 Thread Greg Wooledge
On Fri, Dec 17, 2010 at 09:47:00AM +, Marc Herbert wrote: > This is more or less > the type of problems I had in mind: > > http://hea-www.harvard.edu/~fine/Tech/cgi-safe.html Wow, there is some atrocious code on that page (being shown as "what not to do"). I have no doubt that code just lik

Re: cd with multiple arguments?

2010-12-17 Thread Greg Wooledge
On Fri, Dec 17, 2010 at 12:47:49PM -0600, Illia Bobyr wrote: > I worked on a pretty huge project written 99% in TCL. TCL looks is very > much like Bash, except that, I would say, it is cleaner in the quoting area. The substantial difference is that bash does word splitting and globbing on the re

Re: exit status question

2010-12-20 Thread Greg Wooledge
On Mon, Dec 20, 2010 at 10:38:11AM -0800, Curtis Doty wrote: > The workaround of using ((++i)) seems to work. What if i starts at -1? > Sounds like this is a FAQ. I have a page at http://mywiki.wooledge.org/BashFAQ/105 in fact.

Re: wildcard characters being evaluated improperly?

2010-12-23 Thread Greg Wooledge
On Wed, Dec 22, 2010 at 09:53:32PM -0500, Chet Ramey wrote: > I suspect that ssh is invoking a shell, which is performing the expansion. Yes, that is precisely what happens. A shell on the remote system performs a second parsing. http://mywiki.wooledge.org/BashFAQ/096 for more hints.

Re: Manual: variable SIGWINCH has no definition

2010-12-27 Thread Greg Wooledge
On Mon, Dec 27, 2010 at 04:42:14PM +0100, Christophe Jarry wrote: > today, I found variable SIGWINCH has no definition. That's not a variable name. It's the name of a signal. See `kill -l' or `man 7 signal' (or wherever the definition of signals resides on your operating system).

Re: List of keys of an associative array

2011-01-03 Thread Greg Wooledge
On Fri, Dec 31, 2010 at 10:56:35AM +0100, dnade@orange-ftgroup.com wrote: > Ha. Indeed, if i use declare ???A, it works. > > But why is bash letting me use foo[bar]=something in the first place, if I > don???t declare foo as an associative array ? > Maybe the bug???s here. As Pierre said, fo

Re: Command substitution (backtick) and tab completion

2011-01-05 Thread Greg Wooledge
On Wed, Jan 05, 2011 at 08:21:18AM -0800, chengiz wrote: > So if I get this right, the only time this is a problem is when the > command substitution runs more than once. I'd actually characterize it differently: it's unsafe to run arbitrary commands during tab completion, because bash doesn't kno

Re: Making $! and $? searchable in the man page

2011-01-06 Thread Greg Wooledge
On Thu, Jan 06, 2011 at 10:48:33AM +0100, Vidar Holen wrote: > Hi, > > Finding the meaning of $? and $! in the man page is quite hard for people > not familiar with the layout and bash terminology (this frequently comes > up in Freenode #bash). It would be very helpful for them if you could > simp

Re: for; do; done regression ?

2011-01-10 Thread Greg Wooledge
On Fri, Jan 07, 2011 at 04:17:17AM +0300, Alexander Tiurin wrote: > ~$ time for i in `seq 0 1` ; do echo /o/23/4 | cut -d'/' -f2 ; done > > /dev/null Others have already begun investigating the internal causes of the slowdown. But if you actually want this particular piece of code to run mo

Re: 'help set' missing '--'

2011-01-10 Thread Greg Wooledge
> >>SYNOPSIS > >> set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...] On Mon, Jan 10, 2011 at 09:16:02AM -0500, Chris F.A. Johnson wrote: > On Mon, 10 Jan 2011, Christopher Roy Bratusek wrote: > >Hmm, one could read it as "--" "--a" "--b" and so on, maybe it could be > >improved. > >Agre

field splitting with IFS non-whitespace

2011-01-11 Thread Greg Wooledge
POSIX 2.6.5 Field Splitting [1] says, in part, 1. If IFS is or unset, ... 2. If IFS is null, ... 3. Otherwise, ... b. Each occurrence in the input of an IFS character that is not IFS white space, along with any adjacent IFS white space, shall delimit a field, as described previously.

Re: question about exit command

2011-01-19 Thread Greg Wooledge
On Wed, Jan 19, 2011 at 10:49:47AM +, Davide Brini wrote: > In your second script, the "exit 0" part runs in a subshell, so "exit" exits > that subshell (and I'm somewhat surprised that no semicolon is required after > the closing bracket, but I may have missed something in the grammar). He

Re: question about exit command

2011-01-19 Thread Greg Wooledge
On Wed, Jan 19, 2011 at 01:43:34PM +, Davide Brini wrote: > From wikipedia: > > "Parentheses (singular, parenthesis) ??? also called simply brackets (UK), or > round brackets, curved brackets, oval brackets, or, colloquially, parens..." Oh joy... another weird British thing I wasn't aware of

Re: help builtin bug ???

2011-01-20 Thread Greg Wooledge
On Thu, Jan 20, 2011 at 02:59:49PM +0100, S??awomir Iwanek wrote: > hello, > > and what about this: > > $ help () > > it opens some program in an interactive mode (which one?). Interesting... here, I get the PS2 prompt. arc3:~$ help () > Of course that has nothing to do with the 'help' built

Re: set -m +m -x and the element of chance or is it race conditions?

2011-01-24 Thread Greg Wooledge
On Sun, Jan 23, 2011 at 10:06:40PM +0800, jida...@jidanni.org wrote: > Gentlemen, I am disturbed by these seemingly irregular results, > # perl -pwle 's/\d{4}//' mm|sort|uniq -c > 88 ++ kill Huh? Speak clearly. > from running my program > # cat rt > set -x > set -m > sleep 33& > ki

Re: set -m +m -x and the element of chance or is it race conditions?

2011-01-24 Thread Greg Wooledge
On Mon, Jan 24, 2011 at 10:46:03PM +0800, jida...@jidanni.org wrote: > Thanks Greg, but aren't I acting by the rules? I don't know. I've never before seen anyone flip monitor mode on and off like a toddler that just discovered a light switch. imadev:~$ cat normal #!/bin/

Re: Inconsitent treatment of * (globbing)

2011-01-31 Thread Greg Wooledge
On Sat, Jan 29, 2011 at 12:58:56PM +0100, Pascal Wittmann wrote: > But if I use the expression ".*" in bash, I would expect from the > behaviour of "*", that > ".*" don't include the file "..". But the fact is, that it does in bash. This is done for compatibility with all the other shells. If

Re: How to get control from bash script of a batch job

2011-02-08 Thread Greg Wooledge
On Mon, Feb 07, 2011 at 09:38:42PM -0800, mauede wrote: > I launch a Monte Carlo simulation as a batch job from a bash script: > > exb BEAM_$acc_name $beamin 521icru2 long batch=PBS p=1& You're launching it in the background. > I can still get the process id (I think) through the command: > >

Re: leading 0 inconsistence?

2011-02-14 Thread Greg Wooledge
On Sat, Feb 12, 2011 at 11:57:08AM +0100, Ralf Goertz wrote: > > if [ $((i)) -lt 9 ] ; then echo ok; fi > bash: 08: value too great for base (error token is "08") > > Why is 08 not tried to be interpreted as octal when *numerically* compared > using test? s/not // in your question, I assume. Bec

Re: PS1 has ruined line wrap

2011-02-14 Thread Greg Wooledge
On Sat, Feb 12, 2011 at 02:53:31PM -0500, Jonathan Reed wrote: > An old thread but I found a way around this by adding a line to my bashrc: > > echo -ne "\033]0; `whoami` @ `hostname` \007" ~/.bashrc is only sourced at the beginning of each interactive non-login shell (and, one hopes, also from y

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_

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 a

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=12752

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

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 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 the "it" in

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 associat

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 "wo

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 writes: > > > On Fri, Feb 18, 2011 at 10:32:13PM +0100, Peter Hofmann wrote: > >> > >> $ echo "$(echo "{1..3}")" > >> 1 2 3 > >> > >> H

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. I

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 use

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

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, an

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: quoting issue in GCC's gcc/config.gcc ?

2011-03-03 Thread Greg Wooledge
On Thu, Mar 03, 2011 at 06:41:00PM +0100, Matthias Klose wrote: > replacing > case X"${with_cpu}" in > with > case X${with_cpu} in > > lets the match suceed with bash-4.2.6. bash-4.1.x works with both variants. Confirmed here: imadev:~$ bash-4.1.9

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

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

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 ma

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"

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 com

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"' > -DSTANDARD_UTILS_PATH='"

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 e

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 examp

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 instead of killall -HUP 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: > > $ p

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 t

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 pass

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-e

Re: Why is command substitution happening?

2011-04-12 Thread Greg Wooledge
f input you are feeding it. Your attempt is doomed. On Tue, Apr 12, 2011 at 09:26:05AM -0600, Bill Gradwohl wrote: > On 04/12/2011 08:03 AM, Greg Wooledge wrote: > > > Not good. You're piping filenames into bash and letting bash parse them > > as commands. > Not exa

Re: Cross-version regular expression...

2011-04-13 Thread Greg Wooledge
On Wed, Apr 13, 2011 at 11:19:22AM -0700, Ray Van Dolson wrote: > I'm trying to get regular expression matching working on both bash v3 > as well as v4. Put the RE in a variable. > The following works on v4 (under RHEL6), but not under bash 3.00.15 > (under RHEL4): > > [[ "6Server" =~ ([0-9]+)(.

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 > > Intere

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 progra

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 ge

Re: bug on [A-Z] and [a-z]

2011-05-02 Thread Greg Wooledge
On Sun, May 01, 2011 at 09:17:49PM -0500, Jonathan Nieder wrote: > Hi, > > ri...@inf.ufpr.br wrote: > > > When running "echo [A-Z]*" , it shows all files/dirs of current > > directory, not only those starting with capital letters. I tried > > different locales such as: POSIX, C, en_U

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

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

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 sa

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

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

Re: accents

2011-05-09 Thread Greg Wooledge
On Mon, May 09, 2011 at 04:46:14PM +0200, Thomas De Contes wrote: > Description: > > 1 > when i do > PS1="&# $PS1" > then I have problems since there is some accents in my command lines : What is the value of PS1 before you prepend ampersand-hash-space to it? What does the ampersand-hash-space h

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 i3

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

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

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 inne

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\n"hi mom"\n' imadev:~$

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 ba

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

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 > Win&cygwin 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 li

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: http://pubs.opengroup.org/onlinep

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 awk

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 : > > 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 didn't write the

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 processi

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 ima

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:

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 len

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 termina

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