Re: mention what characters need to be escaped inside [...]

2009-05-04 Thread Greg Wooledge
On Mon, May 04, 2009 at 12:34:19AM +0800, jida...@jidanni.org wrote: > Maybe mention in the man page at >[...] Matches any one of the enclosed characters... > that one will need to backslash at least any spaces used inside it: > $ ls [^ ] > ls: cannot access [^: No such file or directory

Re: grep remove "no such file or directory"

2009-05-06 Thread Greg Wooledge
On Wed, May 06, 2009 at 04:03:51PM +0200, Roman Rakus wrote: > On 05/06/2009 02:14 PM, cseguino wrote: > > $ find . | xargs grep -v "No such file or directory" | grep "StateRB" > > grep: > >./Tiger/codebase/netmarkets/jsp/ext/eurocopter/tiger/change/.svn/text-base/Copy: > >No such file or

Re: best indirect assign of scalar and array variables

2009-05-07 Thread Greg Wooledge
On Wed, May 06, 2009 at 04:53:27PM -0700, J. Greg Davidson wrote: > What's the best way to update a variable indirectly, e.g. when its name is > passed to an update function? http://mywiki.wooledge.org/BashFAQ/006

Re: Is this exploitable?

2009-05-11 Thread Greg Wooledge
On Mon, May 11, 2009 at 10:35:18AM +1000, Jon Seymour wrote: > I am trying to parse untrusted strings and represent in a form that > would be safe to execute. printf "%q" > cmd="echo" > for a in "$@" > do > cmd="$cmd '${a/\'/''}'" > done > echo "$cmd" > eval "$cmd" http://mywiki.wooledge.org

Re: Is there any mutex/semaphore mechanism in shell scripts?

2009-05-21 Thread Greg Wooledge
On Wed, May 20, 2009 at 12:34:42PM -0700, jjjaime wrote: > FUNCTION_1 & > FUNCTION_2 > FUNCTION_3 > > So, to speed up the execution of the script, I want FUNCTION_1 and > FUNCTION_2 in parallel. But the script fails when FUNCTION_2 ends before > FUNCTION_1. Why? > Is there any mechanism for sync

Re: bash script error in array definition.

2009-05-27 Thread Greg Wooledge
On Wed, May 27, 2009 at 03:33:10AM -0700, straygrey wrote: > Please tell me what is wrong with the following line that I have in a bash > script:- > [code] > TODAYDATE=`date +"%Y%m%d"` > declare -a FiLeS=( $TODAYDATE.TeleformDB.tar.bz2 > $TODAYDATE.TeleformDB2.tar.bz2 ) > [/code] > When I run it I

Re: Regex matching oddity (bug, or 'unexpected feature' or...?)

2009-05-28 Thread Greg Wooledge
On Thu, May 28, 2009 at 12:58:10PM -0700, Linda Walsh wrote: > operator caused a failure in matching. I.e.: > if [[ "$Var"=~"+([:digit:])" ]] ; then ... > worked. No, this is incorrect. You need spaces around the =~ so that it's parsed as three separate things, rather than one thing. Your

Re: Using unset to destroy array elements doesn't work with 'nullglob' set

2009-06-05 Thread Greg Wooledge
On Fri, Jun 05, 2009 at 08:35:15AM -0700, Francis Moreau wrote: > unset foo[0] This is a problem in your script, unfortunately. Even without nullglob, this can still fail if you happen to have a file named foo0 in your current working directory, which would be matched as a glob. For total safety

Re: printf has weird behaviour when parsing zero padded numbers

2009-06-22 Thread Greg Wooledge
On Fri, Jun 19, 2009 at 11:05:27AM -0700, bitozoid wrote: > >         edua...@ceo ~ $ printf "%02d\n" 8 > >         -bash: printf: 8: invalid number > Sorry, not a bug, but octal representation. Really sorry. Others will make the same mistake (it's very common), so for the benefit of peop

Re: feature request: more complete set -e

2009-06-29 Thread Greg Wooledge
On Mon, Jun 29, 2009 at 12:45:29AM +0200, Marc Weber wrote: > > echo `expr $var - 1` > I think that this is bad. expr should do some calculation. If the > calculation fails (eg devision by zero) the return value should be non > zero. You'd think so, but alas, the people who made expr(1) had a diff

Re: feature request: more complete set -e

2009-06-30 Thread Greg Wooledge
On Tue, Jun 30, 2009 at 09:58:45PM +0200, Marc Weber wrote: > How is this done? > > CHK0="test $? == 0" > my_important_task; $CHK0 || exit 1 You'd need single quotes instead of double there. (And == is illegal in Bourne/POSIX shell test commands; only bash tolerates it.) You could also use a fu

Re: $\n doesn't get expanded between double-quotes

2009-07-06 Thread Greg Wooledge
On Fri, Jul 03, 2009 at 01:01:47PM -0400, Chris F.A. Johnson wrote: > NL=$'\n' > string="This is a$NLmulti-line$NLstring" Of course you would need curly braces for that. NL=$'\n' string="This is a${NL}multi-line${NL}string"

Re: Possible Feature Requests (unsource, exchange)

2009-07-07 Thread Greg Wooledge
On Tue, Jul 07, 2009 at 08:16:50PM +0200, Christopher Roy Bratusek wrote: > unsource: the opposite of source (while source is making functions > publically available, unsource would remove them) You can "unset -f" a function. You could source a script-file that contains a bunch of "unset -f foo"

Re: Possible Feature Requests (unsource, exchange)

2009-07-08 Thread Greg Wooledge
> > # Usage: exchange varname1 varname2 > > exchange() { > >local tmp > >[[ $1 = *[^[:alnum:]_]* || $1 = [0-9]* ]] && > > { echo "Naughty naughty" >&2; return 1; } > >[[ $2 = *[^[:alnum:]_]* || $2 = [0-9]* ]] && > > { echo "Naughty naughty" >&2; return 1; } > >eval tmp=\$$

Re: [OT] regarding 'time' builtin

2009-07-20 Thread Greg Wooledge
On Fri, Jul 17, 2009 at 06:42:03PM -0400, Chris Jones wrote: > Sometimes I wonder if Greg is a "real" person.. not a smart program that > can generate the correct answers to all the questions you had about bash > utilization - and may have been too shy to ask. Either I'm

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

2009-07-20 Thread Greg Wooledge
On Fri, Jul 17, 2009 at 02:53:21PM -0700, Erik Olof Wahlstrom wrote: > #!/bin/bash > BACKUP_DIR="/media/disk/AUTOMATED_BACKUPS/DB_DAILY" > > CURRENT_DIR=$BACKUP_DIR/`date +%d` # See how you call date here without an explicit path? That's good. > DATABASES="$(/usr/bin/mysql -uUsername -pPasswo

Re: time seg fault

2009-07-23 Thread Greg Wooledge
On Thu, Jul 23, 2009 at 09:59:48AM -0400, Justin Williams wrote: > Unfortunately, if I try to strace it (strace time ls), I get command not > found. ''strace time ls'' will try to run the external command ''time'' which apparently you haven't got installed. (Which is probably good in this case, a

Re: Error with file descriptor

2009-08-03 Thread Greg Wooledge
On Sat, Aug 01, 2009 at 07:36:36PM +0200, Aljosha Papsch wrote: > ModManager() { > ClearFiles -4 > echo "zenity --list --window-icon=\"${run_path}icon.png\" > --width=\"650\" --height=\"350\" --title=\"${modmanager[${lang}]}\" > --text=\"${RegMods[${lang}]}:\" --column=\"${no[${lang}]}\" > --c

Re: Bash does not read up the whole script which it is currently executing

2009-08-04 Thread Greg Wooledge
On Tue, Aug 04, 2009 at 08:23:16AM -0700, John Reiser wrote: > On 08/04/2009 12:48 AM, fam...@icdsoft.com wrote: > > The problem is that Bash does not read up the whole script which it > > is currently executing. > > As a result of this, if we update the script file with a newer > >

Re: Assigning to multiple variables on same line

2009-08-13 Thread Greg Wooledge
On Thu, Aug 13, 2009 at 02:45:51AM -0400, Mike Frysinger wrote: > i dont think word expansion occurs first, otherwise wouldnt this break: > foo() { > unset b c > f="a b=" > local a=$f c= As I understand it, this is what happens: 1) The parser separates out the tokens that consti

Re: wget command with simple url makes bash crash

2009-08-26 Thread Greg Wooledge
On Tue, Aug 25, 2009 at 02:40:24PM +0200, Oskar Hermansson wrote: > wget > http://www.kohanaphp.com/download?modules%5Bauth%5D=Auth&vendors%5Bmarkdown%5D=Markdown&languages%5Ben_US%5D=en_US&format=zip > > If the command is placed in a file instead, the file is successfully > downloaded: >

Re: manpage note? weird strings that appear to be equal but create haywire comparisons?

2009-08-26 Thread Greg Wooledge
On Wed, Aug 26, 2009 at 02:45:39AM -0700, Linda Walsh wrote: > I was scripting and fixing some permissions in Win, > and had a var 'c' set to (no quotes in the var): 'C\windows\system32' How did you assign this value? Did you read it from a file? Did you type a specific bash command? > # ech

Re: manpage note? weird strings that appear to be equal but create haywire comparisons?

2009-08-26 Thread Greg Wooledge
On Wed, Aug 26, 2009 at 04:36:42PM +0300, Pierre Gaston wrote: > Thanks, I agree with that, I'm sorry I should have been more explicit, > what was not clear to me was where this special role of the \ is explained, > Because if you use literals [[ something = \* ]] is the same as [[ > something = "

Re: how to keep newlines in ``

2009-08-26 Thread Greg Wooledge
On Wed, Aug 26, 2009 at 03:04:16PM -0400, Sam Steingold wrote: > foo=`ls` > echo $foo echo "$foo"

Re: mysqldump usage in bash

2009-08-28 Thread Greg Wooledge
On Thu, Aug 27, 2009 at 06:13:38AM -0700, Arenstar wrote: > temp="mysqldump -h $DBSource -u $USER -p$PASS $DB $TABLE --where='$Field > > $VarStart AND $Field < $VarEnd' > $TABLE$DumpName" > exec $temp The obvious problem here is that you want the last ">" to be treated as a redirection op

Re: mysqldump usage in bash

2009-08-28 Thread Greg Wooledge
On Fri, Aug 28, 2009 at 07:06:52AM -0700, Arenstar wrote: > What effects can eval have? that i am unaware of. In fact ive never used > eval before, it just wasnt neccessary.. > Thank you for your interesting reply > > query="mysqldump -h $DBSource -u rx -p $DB $TABLE --where '$Field > > $

Re: ulimit and ssh?

2009-09-08 Thread Greg Wooledge
On Tue, Sep 08, 2009 at 11:39:02AM -0700, peter360 wrote: > Thanks for the explanation. So my understanding of the way ssh works is > still incorrect. I am confused about at which point the two parameters, > "-c" and "ulimit -a" were converted into three, "-c", "ulimit", and "-a". I > guess I n

Re: Strange compgen behaviour

2009-09-25 Thread Greg Wooledge
On Thu, Sep 24, 2009 at 03:05:07PM -0700, Mathias Dahl wrote: > I did not find any generic way to quote/escape file names so I > hardcoded some chars I know exist in my file names and used sed: printf %q "$filename" will either insert backslashes in front of all the shell metacharacters, or $'...

Re: extglobs in case constructs

2009-10-01 Thread Greg Wooledge
On Thu, Oct 01, 2009 at 04:17:33PM +0200, Martin von Gagern wrote: > #!/bin/bash > > shopt -s extglob > f() { > if [[ $v == a@(a|b|c)c ]]; then > case $v in > a@(a|b|c)c) You're using extglobs inside a function, and extglob wa

Re: redirection after braced block

2009-10-05 Thread Greg Wooledge
On Mon, Oct 05, 2009 at 07:55:33PM +0200, clemens fischer wrote: > >> { > >> ... a number of commands > >> } 2>&1 | ${prog_log} "${logfile}" > yeah ok, but the commands really are not executed. I have an option > dry-run in the script, which sets "prog_log=true". Then there are > a bun

Re: ${!vname} not documented

2009-10-06 Thread Greg Wooledge
On Tue, Oct 06, 2009 at 03:25:31AM -0400, Mike Frysinger wrote: > On Tuesday 06 October 2009 01:39:56 Mikel Ward wrote: > > It would be more obvious if it had a paragraph directly below > > ${parameter} saying something like: > > > >${!name} > >Indirect expansion. name is expanded

Re: Cannot form valid test expressions that involve brackets as string comparison targets

2009-10-08 Thread Greg Wooledge
On Wed, Oct 07, 2009 at 08:07:19PM +1030, Lyall Pearce wrote: > Description: > Cannot form expressions which involve left or right brackets. Parentheses? > Repeat-By: > > basePic="(2008-04)" > if [ "${basePic:0:1}" = '(' -a "${basePic:4:1}" = ')' ] > then > echo "Got

Re: "Sed" Question

2009-10-14 Thread Greg Wooledge
On Wed, Oct 14, 2009 at 12:24:30PM -0600, Bob Proulx wrote: > Pierre Gaston wrote: > > Please consider asking in a sed mailing list like: > > http://sed.sourceforge.net/#mailing > > or maybe in the usenet group comp.unix.shell > > I would think help-gnu-ut...@gnu.org would be the better place to a

Re: bash reads on device when it shouldn't...

2009-10-23 Thread Greg Wooledge
On Thu, Oct 22, 2009 at 06:47:43PM +, K??rlis Repsons wrote: > I've set up a system, which has some disks, that are not always used, but are > always mounted. OS and program files are all in other place and the only > program, which still reads some blocks (echo 1 > /proc/sys/vm/block_dump),

Re: OT: Getting MySQL fields with embedded spaces into array

2009-10-28 Thread Greg Wooledge
On Wed, Oct 28, 2009 at 06:04:00AM -0400, Gerard wrote: > COM_LINE="-u${SQL_USER} -p${SQL_PASSWORD} -h ${HOST} ${NO_COLUMN_NAME}" > table=MyTable > DECLARE_STATEMENTS=($(mysql ${COM_LINE} -i -e"use ${DB}; SELECT defaults FROM > "${table}" WHERE 1;")) You're populating an array with each word (not

Re: [OT] Re: how to start in "overwrite-mode"

2009-10-28 Thread Greg Wooledge
On Wed, Oct 28, 2009 at 02:00:53PM +, Stephane CHAZELAS wrote: > I can understand it. I was more curious about the origins. After > all, that breaks Bourne backward compatibility (in a shell > called Bourne-again shell) Bourne shell has no functions at all. > Has there be historical versions

Re: OT: Getting MySQL fields with embedded spaces into array

2009-10-29 Thread Greg Wooledge
On Thu, Oct 29, 2009 at 11:49:11AM -0400, Gerard wrote: > Are you sure? Using: IFS=$(echo) seems to set IFS to a newline here. imadev:~$ IFS=$(echo) imadev:~$ printf "%s" "$IFS" | od -t x1 000 imadev:~$ printf "\n" | od -t x1 000a 001 imadev:~$ echo ${#IFS} 0 imadev:~$ unset IFS A

Re: value too great for base (error token is "0008")

2009-11-04 Thread Greg Wooledge
On Tue, Nov 03, 2009 at 05:37:45PM -0700, Bob Proulx wrote: > Dobromir Romankiewicz wrote: > > bash: 0008: value too great for base (error token is "0008"). > Numbers with leading zeros are read as octal constants. Octal is > composed of '0' through '7'. The number '8' is too large to be an > oc

Re: Error handling question

2009-11-09 Thread Greg Wooledge
On Mon, Nov 09, 2009 at 08:39:57AM +0200, Ciprian Dorin, Craciun wrote: > But then how can I solve the problem? (How about `()` which > clearly is a new shell instance.) The problem being "how to use set -e in a consistent manner across all shells"? You can't. set -e is unpredictable, unreli

Re: Error handling question

2009-11-09 Thread Greg Wooledge
On Mon, Nov 09, 2009 at 03:49:09PM +0200, Ciprian Dorin, Craciun wrote: > Unfortunately I'm not subscribed to this mailing list. Could you > point me to the right thread? http://lists.gnu.org/archive/html/bug-bash/2009-11/threads.html And... pretty much every month, especially since bash 4 ch

4.0 patch 25 breaks older gcc

2009-11-11 Thread Greg Wooledge
make[1]: Entering directory `/var/tmp/bash-4.0/lib/glob' rm -f glob.o /net/appl/gcc-3.3/bin/gcc -c -DHAVE_CONFIG_H -DSHELL -I. -I../.. -I../.. -I../../include -I../../lib -DHPUX -g -O2 glob.c glob.c:1026:69: missing terminating ' character make[1]: *** [glob.o] Error 1 make[1]: Leaving directory

siglist.c missing #include "bashintl.h"

2009-11-11 Thread Greg Wooledge
/net/appl/gcc-3.3/bin/gcc -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde -L./lib/malloc -L./lib/sh-g -O2 -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcm

4.0 core dump from printf -v foo %s bar

2009-11-11 Thread Greg Wooledge
The other two messages I sent today were just things I encountered while bringing my bash 4.0 up to the current patch level. This is the real problem I've been chasing. imadev:/var/tmp/bash-4.0$ bash-3.1.17 -c 'printf -v foo %s bar' imadev:/var/tmp/bash-4.0$ bash-4.0.10 -c 'printf -v foo bar' ima

Re: 4.0 core dump from printf -v foo %s b

2009-11-12 Thread Greg Wooledge
On Wed, Nov 11, 2009 at 09:41:29PM -0500, Chet Ramey wrote: > If your version of vsnprintf doesn't behave like that, I claim it's a > bug. The Posix and C standards explicitly allow the buffer to be NULL > if the size argument is 0, and guarantee that no data will be written > in this case. Thank

[PATCH] Re: 4.0 core dump from printf -v foo %s b

2009-11-12 Thread Greg Wooledge
On Thu, Nov 12, 2009 at 02:37:58PM -0500, Chet Ramey wrote: > I try to write to the current (well, ten-year-old) standards. The > replacement in lib/sh/snprintf.c behaves as C99 specifies; you might try > using it by #undefing HAVE_VSNPRINTF and HAVE_SNPRINTF in config.h. Ah, wonderful. I wasted

Re: bash40-011 patch can't be applied cleanly

2009-11-19 Thread Greg Wooledge
On Wed, Nov 18, 2009 at 06:54:01PM -0800, Sergei Steshenko wrote: > My script was applying patches from 'bash-4.0-patches' directory, not from > 'bash-4.0' one, and maybe this was my mistake. Yes. You should always be in the source directory you're patching, when you apply a patch. The only ques

Re: Bash 4 and ECHOCTL

2009-11-23 Thread Greg Wooledge
On Thu, Nov 19, 2009 at 06:32:49PM +0100, Joachim Schmitz wrote: > In siglist.c the compiler complained bitterly about having to convert the > reseult of _() into a char * (sometimes comming from int, somtimes coming > from const char *) My nasty workaround: The correct fix for that one is to #i

Re: sudo: command: not found

2009-11-23 Thread Greg Wooledge
On Sun, Nov 22, 2009 at 06:14:56PM +0800, wrote: > run the command "drcomd" ,successful! > > but run command "sudo drcomd" ,return "sudo : drcomd: command not found" Not really a bash bug. > under both (fedora)the PATH is > /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/

Re: printf "%q" and $'...'

2009-11-25 Thread Greg Wooledge
> On 25 Nov 2009, at 08:19, Antonio Macchi wrote: > > Hi, I'm using older bash 3.2.39, so please forgiveme if in your newer bash > > this issue does not arise. On Wed, Nov 25, 2009 at 08:25:00AM +0100, Maarten Billemont wrote: > As for NUL out outputting anything in your result, the cause is C-st

Re: printf "%q" and $'...'

2009-11-25 Thread Greg Wooledge
On Wed, Nov 25, 2009 at 02:35:51PM +0100, Antonio Macchi wrote: > it sounds strange, beacuse > > $ find . -print0 | while read -d $'\x00'; do touch "$REPLY"; done > > works fine. > > > but if I try to "output" $'\x00', I can't. There's a lot going on here, so I'll try to cover it as best I can

Re: IFS handling and read

2009-11-30 Thread Greg Wooledge
On Mon, Nov 30, 2009 at 11:46:03AM +0100, Lhunath (Maarten B.) wrote: > Don't use pipelines to send streams to read. Use file redirection instead: > > Instead of ''command | read var'' > Use ''read var < <(command)'' > > I hardly see a need to change the existing implementation. Or for the orig

Re: <( error

2009-11-30 Thread Greg Wooledge
On Sat, Nov 28, 2009 at 02:57:45PM +0100, Antonio Macchi wrote: > but, if you don't have hd (hexdump) how can you see the content of a, > for example, strange file > > i mean > > $ ls -l > total 0 > -rw-r--r-- 1 user1 user1 0 2009-11-28 14:56 ? > > $ hd <(ls) > 09 0a

Re: <( error

2009-11-30 Thread Greg Wooledge
On Sat, Nov 28, 2009 at 02:18:37PM +0100, Antonio Macchi wrote: > $ hd <(echo -en \\0{0..3}{0..7}{0..7}) As for this, I wonder if you understand how bash handles this. I know it certainly wasn't obvious to me! Due to the way the parsing is done, the brace expansions inside the proces substitution

Re: operators available in bash versions

2009-11-30 Thread Greg Wooledge
On Mon, Nov 30, 2009 at 11:15:38AM -0500, Mike Frysinger wrote: > On Monday 30 November 2009 06:12:35 Gerard wrote: > > I need to know if " $(< " also works on Bash < 4. > > it's been around for pretty much all time. bash-2 had it for sure, and that > is ancient. It doesn't exist in bash 1.14.7

Re: IFS handling and read

2009-11-30 Thread Greg Wooledge
On Mon, Nov 30, 2009 at 04:21:33PM +, Marc Herbert wrote: > Chris F.A. Johnson a écrit : > >Why should it be the last element of a pipeline that is executed in > >the current shell and not the first? > > Because that's POSIX' choice? Because that's what Korn shell does. (But not pdks

Re: operators available in bash versions

2009-11-30 Thread Greg Wooledge
On Mon, Nov 30, 2009 at 12:35:32PM -0500, Mike Frysinger wrote: > On Monday 30 November 2009 12:12:17 Greg Wooledge wrote: > > On Mon, Nov 30, 2009 at 11:15:38AM -0500, Mike Frysinger wrote: > > > On Monday 30 November 2009 06:12:35 Gerard wrote: > > > > I need to

Re: output redirection with process substitution asynchronous?

2009-12-07 Thread Greg Wooledge
> pjodrr wrote: > > how can I prefix every line of output of some command with a > > timestamp? Mark Herbert wrote: > What is wrong with the following: > > prefix_with_date () > { > while read; do > printf '%s: %s\n' "$(date)" "$REPLY"; > done > } > > seq 4 | prefix_with_date

Re: bash is not capable of comparing of strings and real numbers

2009-12-08 Thread Greg Wooledge
On Mon, Dec 07, 2009 at 05:08:02PM -0800, DennisW wrote: > Since printf understands floats (or acts like it does), you can use it > plus a little care and luck to do float comparisons in Bash: > [...] > $ printf -v a "%08.2f" $a > $ printf -v b "%08.2f" $b > $ [[ $a < $b ]] && echo true || echo fal

Re: Command substitution reduce spaces even in strings

2009-12-08 Thread Greg Wooledge
On Tue, Dec 08, 2009 at 02:01:23PM +0100, ma...@fiz15.jupiter.vein.hu wrote: > $ echo $(echo "'alfa beta'") > 'alfa beta' > > Instead of 'alfa beta' with double space. echo "$(echo "'alfa beta'")"

Re: best way to test for empty dir?

2009-12-10 Thread Greg Wooledge
On Thu, Dec 10, 2009 at 05:31:20PM +, Marc Herbert wrote: > Does anyone know a more elegant way to check for file existence? > Something that does not fork a subshell. And is also more readable > maybe. And is obviously not much longer. shopt -s nullglob files=(*) if (( ${#files[*]} == 0 )); t

Re: best way to test for empty dir?

2009-12-10 Thread Greg Wooledge
On Thu, Dec 10, 2009 at 05:37:04PM -0200, Matias A. Fonzo wrote: > Maybe you want the Chris F.A Johnson's implementation [1]: > > set -- "/tmp/emptydir"/* > [[ -f $1 ]] && echo non-empty || echo empty; > > References: > [1] > http://www.issociate.de/board/goto/866027/checking_if_a_directory_is_e

Re: best way to test for empty dir?

2009-12-11 Thread Greg Wooledge
On Fri, Dec 11, 2009 at 01:09:09PM +0100, Antonio Macchi wrote: > > this could be another way to accomplish this > > empty_dir() { > eval test \" $1/* \" == \"" $1/* "\"; > } > > (excluding invisible files...) This one also has the problem of failing if the directory contains a single file n

Re: best way to test for empty dir?

2009-12-11 Thread Greg Wooledge
On Fri, Dec 11, 2009 at 04:16:13PM +, Marc Herbert wrote: > In case anyone is interested my winner (so far) is: > > exists() > { > [ -e "$1" -o -L "$1" ] > } > > if exists foo/*; then > for f in foo/*; do > ... > done > fi What if there's a subdirectory or something and you'd lik

Re: Bash-4.1-rc1 available for FTP

2009-12-22 Thread Greg Wooledge
On Tue, Dec 22, 2009 at 08:46:14AM -0500, Chet Ramey wrote: > The first release candidate of bash-4.1 is now available with the URL > > ftp://ftp.cwru.edu/pub/bash/bash-4.1-rc1.tar.gz The syslog feature (in config-top.h) appears to be enabled by default. This is quite shocking

Re: Bash-4.1-rc1 available for FTP

2009-12-22 Thread Greg Wooledge
On Tue, Dec 22, 2009 at 02:23:47PM -0500, Mike Frysinger wrote: > On Tuesday 22 December 2009 08:46:14 Chet Ramey wrote: > > The first release candidate of bash-4.1 is now available with the URL > > top level Makefile.in is missing pathnames.h dependency info for > builtins/evalstring.o and built

Re: GPL incompatibility? examples/loadables/getconf.c

2009-12-28 Thread Greg Wooledge
On Fri, Dec 25, 2009 at 05:28:43PM -0800, Julius Davies wrote: > This file in the source contains a BSD license with an advertising clause: > > bash-4.0/examples/loadables/getconf.c > > > I'm curious if this is a problem, since Bash is mostly GPL version 3 (or > later). The examples/loadables/

Re: $(pwd) != $(/bin/pwd)

2010-01-05 Thread Greg Wooledge
On Mon, Jan 04, 2010 at 01:25:50PM +, Stephane CHAZELAS wrote: > >> da...@thinkpad ~/foo $ echo $PWD > >> /home/darkk/foo > Well, if I read > http://www.opengroup.org/onlinepubs/9699919799/utilities/pwd.html > correctly, bash pwd should output /home/darkk/bar in that case > as $PWD does *not*

Re: can't compile bash 4.1 under Solaris 8/9

2010-01-07 Thread Greg Wooledge
On Thu, Jan 07, 2010 at 12:22:12PM +0100, Yann Rouillard wrote: > ./printf.def:175: error: conflicting types for 'vsnprintf' > Maybe you could first send me the config.log/config.h generated on > Solaris 8 so I can compare with mine ? It might be more useful to compare your stdio.h header file i

Re: can't compile bash 4.1 under Solaris 8/9

2010-01-07 Thread Greg Wooledge
On Thu, Jan 07, 2010 at 09:03:19AM -0500, Chet Ramey wrote: > *** ../bash-4.1/builtins/printf.def 2009-11-20 15:31:23.0 -0500 > --- builtins/printf.def 2010-01-07 08:50:06.0 -0500 > *** > *** 173,177 > > #if !HAVE_VSNPRINTF > ! extern int vsnprintf __P(

Re: weird bash pipe behavior

2010-01-21 Thread Greg Wooledge
On Wed, Jan 20, 2010 at 07:34:35AM -0800, CptDpondo wrote: > mencoder 2>&1 | tr '\r' '\n' | grep -v -B 1 '^Pos' > > this eventually creates the correct output, but it's buffered until > mencoder completes. I have no idea why; the tr command streams > without buffering and I've used grep for

Re: weird bash pipe behavior

2010-01-21 Thread Greg Wooledge
On Thu, Jan 21, 2010 at 06:11:10AM -0800, Yan Seiner wrote: > Greg Wooledge wrote: > >grep definitely has this buffering behavior. If you're using GNU grep, > >you can give it the --line-buffered option to change this, at least > >according to whichever contributor

Re: variable assignment in string returning function

2010-01-27 Thread Greg Wooledge
On Wed, Jan 27, 2010 at 03:07:40PM +0200, Pierre Gaston wrote: > On Wed, Jan 27, 2010 at 2:49 PM, Sharuzzaman Ahmat Raslan > wrote: > > Somehow, the backtick for foo() execute the function, echoing the correct > > output, but fails to set the variable $gang to the correct value. Because of > > tha

Re: Any guide about writing my own bash built-in commands?

2010-02-01 Thread Greg Wooledge
On Sat, Jan 30, 2010 at 03:17:22PM +0100, Joachim Schmitz wrote: > Clark J. Wang wrote: > >Hi all, > > > >I want to write my own built-in bash commands but I cannot find any > >info about that in bash manual. Anyone has any idea? > > Have a look into the .def files in the builtins directory of bas

Re: Grepping an array in bash, odd/buggy behavior when using shopt and '!'

2010-02-03 Thread Greg Wooledge
On Tue, Feb 02, 2010 at 07:29:25PM -0800, Davey E wrote: > FOO[3]="ABZ555" > shopt -s extglob > echo '${f...@]/#!(ABZ555)/}' results in: ${f...@]/#!(ABZ555)/} > When run, I see: > ${f...@]/#!(ABZ555)/} results in: 5 You are trying to use a substitution operator to perform matching, which is not

Re: Error when script uses CRLF line endings w/ if stmt

2010-02-05 Thread Greg Wooledge
On Thu, Feb 04, 2010 at 11:54:51PM -0600, Evan Driscoll wrote: > Why not make Bash consider \r\n a legitimate line ending? What possible > reason could there be for treating carriage return characters as it does > now? Well, the most literal reason is that the shebang (#!/program) line will not

Re: colored bash prompts seem to confuse readline

2010-02-09 Thread Greg Wooledge
On Tue, Feb 09, 2010 at 08:39:49AM -0900, Britton Kerin wrote: > Well ok its not just a plain colored prompt, what I would like to use is > this: > > txtred='\e[0;31m' # Red > bldgrn='\e[1;32m' # Green > txtrst='\e[0m'# Text Reset > PROMPT_COMMAND=' \ > if [ $? -eq 0 ];

Re: + vs. [^/]* - Regular Expression bug?

2010-02-11 Thread Greg Wooledge
On Tue, Feb 09, 2010 at 09:18:47PM -0800, DennisW wrote: > * means zero or more characters. It found zero and stopped. You could > do: > > [[ '/home/' =~ /([^/]*) ]]; echo ${BASH_REMATCH[1]} Oh, is he trying to get the first non-null component of a /-delimited pathname? I can never tell any more

Re: process substitution and trailing file descriptors

2010-02-11 Thread Greg Wooledge
On Thu, Feb 11, 2010 at 03:04:30AM -0800, Ian wrote: > The manual suggests I could move and close file descriptors with > > [n]>&digit- > > but I would need the equivalent of > > command1 >&>(...)- > > Digit might very well mean (just a) digit but here the process > substitution, of course

Re: undefined reference to `__strtoll'

2010-02-11 Thread Greg Wooledge
On Thu, Feb 11, 2010 at 12:58:46PM -0500, Dave Moore wrote: > Machine: hppa2.0w > OS: hpux11.00 > Compiler: gcc > Bash Version: 4.1 > Patch Level: 0 I don't have an HP-UX 11.00 machine to test on, but: > I'm having trouble compiling bash on HP-UX 4.1. I can't figure out how to > work around it.

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

2010-02-12 Thread Greg Wooledge
On Fri, Feb 12, 2010 at 11:56:49AM +0100, Guillaume Outters wrote: > > I usually begin all my scripts with this beast: > > absolutiseScripts() { SCRIPTS="$1" ; echo "$SCRIPTS" | grep -q ^/ || > SCRIPTS="`dirname "$2"`/$SCRIPTS" ; } ; absolutiseScripts "`command -v "$0"`" > "`pwd`/." ; while [ -

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

2010-02-12 Thread 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. I'll get back to that at the end. It also won't handl

Re: FWD: About Bash Script

2010-02-15 Thread Greg Wooledge
On Mon, Feb 15, 2010 at 10:20:05PM +0100, Mart Frauenlob wrote: > > From: Curt > > What I want to do is simply if the destination file exists, instead it > > creates an index number and appends that to the name. > > > > If b.txt exists then a.txt will be renamed to b.txt.1, but if b.txt.1

Re: Variable getopts lost

2010-02-23 Thread Greg Wooledge
On Tue, Feb 23, 2010 at 08:30:16PM +0100, Daniel Bunzendahl wrote: > if [ !$LSEITE ]; then You want: if [ ! "$LSEITE" ] There are probably more errors. This is just the line you mentioned in particular as not working.

Re: echo ^C

2010-02-23 Thread Greg Wooledge
On Tue, Feb 23, 2010 at 10:23:38PM +0100, Freddy Vulto wrote: > Within the bash-completion testsuite, we're trying to synchronize in > between test cases using the string "^C", output by bash on receiving a > SIGINT. > This works fine for bash >= 4 (typing ^C is echoed as "^C"), but on > bash-3 typ

Re: echo ^C

2010-02-24 Thread Greg Wooledge
On Tue, Feb 23, 2010 at 05:23:00PM -0500, Chet Ramey wrote: > That capability (readline echoing the key that generated a signal if the > ECHOCTL bit was set with stty) was not added until bash-4.0. It's a > settable variable in bash-4.1, so you may not want to rely on it. ... Ah, there it is. In

Re: Logically equivalent statements output different results. Suspect problem with 'pipe'.

2010-03-02 Thread Greg Wooledge
On Tue, Mar 02, 2010 at 03:41:36PM +0530, Kalidas Yeturu wrote: > p=0; for lig in `cat a`; do cat b | while read i; do echo "printing $p"; > ((p=$p+1)); done; done > > #outputs(I DO NOT EXPECT p TO BE RESET EACH TIME WHILE RUNS) > printing 0 > printing 1 > printing 2 > printing 0 > printin

Re: unicode aware printf \u and \U switches not supported

2010-03-23 Thread Greg Wooledge
On Mon, Mar 22, 2010 at 02:24:48PM +0100, Thomas Bartosik wrote: > Repeat-By: > tb...@blackknight ~ $ /usr/bin/printf "\u20AC\n" > ? > tb...@blackknight ~ $ type printf > printf is a shell builtin > tb...@blackknight ~ $ printf "\u20AC\n" > \u20AC Must be a GNUism. On HP-U

Re: Data piped to 'mapfile', 'readarray', 'read -a' shell builtins is ignored

2010-03-24 Thread Greg Wooledge
On Wed, Mar 24, 2010 at 04:10:41PM +0200, Pierre Gaston wrote: > On Wed, Mar 24, 2010 at 12:43 AM, Rob Robason wrote: > >$ ls -a | readarray# using the default MAPFILE array > It's a faq, commands in a pipe are executed in a subshell and don't modify > the parent shell. And the wo

Re: printf builtin: '*' broken in conversion spec field width and precision (e.g., "%.*s")

2010-03-25 Thread Greg Wooledge
On Thu, Mar 25, 2010 at 03:32:25AM -0700, Rob Robason wrote: > The printf builtin is broken in many variations of use of '*' (e.g., "%.*s") > in a printf conversion spec to set field width and precision from argument > values. The use of '*' as a field width is not required by POSIX. According

Re: manpage error-Arithmetic Evaluation of numbers with explicit base

2010-03-29 Thread Greg Wooledge
On Mon, Mar 29, 2010 at 02:22:35PM +0200, Thomas Bartosik wrote: > Well OK, I understand. Still I think there should be a difference in the man > page when it comes to brackets. When talking about arrays, the brackets are > NOT an option but mandatory. That's correct. Referencing a specific eleme

Re: Bash sometimes cannot find aliases

2010-03-30 Thread Greg Wooledge
On Tue, Mar 30, 2010 at 02:36:59PM +0800, Clark J. Wang wrote: > After some investigation I could stably reproduce this > problem by following steps (tested with bash 3.1.17, 3.2.39 and 4.1.0): > > bash$ alias xx='echo 142857'### Make sure there isn't an external cmd > named `xx' > bash$ expor

Re: Strings manipulation without using variables

2010-03-31 Thread Greg Wooledge
On Wed, Mar 31, 2010 at 11:03:17AM -0600, Bob Proulx wrote: > Or with GNU sed using the \+ extension: > > FILENAME=$(ls | tail --lines=1 | sed 's/\.[^.]\+$//') > > I assume that 'ls' isn't what you actually are doing, that you have > reduced the test case to something smaller (thank you for tha

Re: Can arithmetic evaluation trap more than just division by zero?

2010-04-06 Thread Greg Wooledge
On Tue, Apr 06, 2010 at 01:29:28PM +0200, Roman Rakus wrote: > Is it possible to add more traps to arithmetic evaluation? > Repeated by: > $((2 ** 63 / -1)) > > Actual result: > SIGFPE (not catched) > > Initial report is https://bugzilla.redhat.com/show_bug.cgi?id=579622 Hmm, I don't get that.

Re: Can arithmetic evaluation trap more than just division by zero?

2010-04-06 Thread Greg Wooledge
On Tue, Apr 06, 2010 at 02:21:05PM +0200, Roman Rakus wrote: > >>$((2 ** 63 / -1)) > I can reproduce it in 4.1.2(1)-release and 4.0.23(1)-release on x86_64 > GNU/Linux. I didn't try on bash 3.2. cyclops:~$ uname -a; echo $BASH_VERSION OpenBSD cyclops.wooledge.org 4.6 GENERIC.MP#81 amd64 4.0.24(1

Re: bash exit command should be unconditional

2010-04-08 Thread Greg Wooledge
On Thu, Apr 08, 2010 at 06:05:05AM -0700, Vadym Chepkov wrote: > A company I work for is trying to migrate their applications to Linux > platform and have selected RedHat as the vendor. Redhat installs bash as the > standard shell : > $ ls -l /bin/sh > lrwxrwxrwx 1 root root 4 Jul 7 2009 /bin/sh

Re: bash exit command should be unconditional

2010-04-08 Thread Greg Wooledge
On Thu, Apr 08, 2010 at 10:07:32AM -0600, Bob Proulx wrote: > Greg Wooledge wrote: > > Migrating FROM something that used Korn shell, I presume? Why not > > just install Korn shell and use #!/bin/ksh on your scripts, if you need > > to rely on Korn shell features? > Whe

Re: How cd to a directory with special characters like environment\<\-?

2010-04-09 Thread Greg Wooledge
On Fri, Apr 09, 2010 at 11:59:20AM -0400, Chris F.A. Johnson wrote: > On Fri, 9 Apr 2010, Marc Herbert wrote: > > Le 08/04/2010 22:58, Peng Yu a ?crit : > > > $ mkdir environment\<\- > > > $ cd environmen\<\- > > > -bash: cd: environmen<-: No such file or directory > > In such situations I find c

Re: Bash and cd

2010-04-12 Thread Greg Wooledge
On Sun, Apr 11, 2010 at 02:56:38PM -0400, Rue U wrote: > The "cd" command/program doesnt work with paths stored in a variable. It does if you quote properly. > If the variable contains the backslash. It should not. It should contain ONLY the actual path you want. > var=/media/New\ Folder\ Here

Re: Strange behavior of IFS?

2010-04-15 Thread Greg Wooledge
On Thu, Apr 15, 2010 at 09:58:42PM +0800, Clark J. Wang wrote: > # cat foo.sh > string=aa:bb:cc > oldIFS=$IFS > IFS=: > for i in "$string"; do >     echo $i > done > IFS=$oldIFS > # bash foo.sh > aa bb cc > # > > I don't understand why the $string was still splitted into words since > it's double

Re: How to start bash without inheriting any environment variables and user level profiles (such as .bash_profile)?

2010-04-28 Thread Greg Wooledge
On Wed, Apr 28, 2010 at 02:38:01PM -0500, Peng Yu wrote: > I'm wondering how to start bash without inheriting any environment > variables and user level profiles (such as .bash_profile). Would you > please let me know what option to use? env - "$(command -v bash)" --noprofile --norc You'd proba

<    5   6   7   8   9   10   11   12   13   14   >