Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Jan Schampera
Clark J. Wang schrieb: > And if the script crashes the dir will be left unlocked. System crashes and kill -9 are the problem. The rest is none. If the area isn't too complex, noclobbered redirection serves well. But if you have other options, they should be used, of course. (doing this on a clu

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Clark J. Wang
On Fri, Apr 16, 2010 at 10:52 AM, Bob Proulx wrote: > Clark J. Wang wrote: > > Bob Proulx wrote: > > > There is also 'lockfile' distributed with 'procmail'. > > > > By using `lockfile' we must make sure that our script will not crash and > > the file is unlocked when the script exits. > > True.

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Bob Proulx
Clark J. Wang wrote: > Bob Proulx wrote: > > There is also 'lockfile' distributed with 'procmail'. > > By using `lockfile' we must make sure that our script will not crash and > the file is unlocked when the script exits. True. That is true of any of the file based locking methods. And advanta

Re: Undocumented usage of printf?

2010-04-15 Thread Clark J. Wang
On Thu, Apr 15, 2010 at 11:43 PM, Eric Blake wrote: > On 04/15/2010 08:21 AM, Clark J. Wang wrote: > > I saw a printf usage from a Linux forum's post: > > > > # printf "%d\n" "'a" > > 97 > > # > > POSIX requires this behavior, so you could claim that this serves as > documentation: > http://www.o

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Clark J. Wang
On Fri, Apr 16, 2010 at 12:57 AM, Bob Proulx wrote: > Eric Blake wrote: > > Clark J. Wang wrote: > > > In C code I can use lockf(), flock(), semaphore and mutex for locking / > > > unlocking. Can bash provide some similar mechanisms? > > > > man 1 flock > > > > If necessary, you may need to insta

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Clark J. Wang
On Fri, Apr 16, 2010 at 12:04 AM, Jan Schampera wrote: > Clark J. Wang schrieb: > > In C code I can use lockf(), flock(), semaphore and mutex for locking / > > unlocking. Can bash provide some similar mechanisms? > > > > For simple things, which don't need to be 1000% rocksolid, you can use > atom

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Clark J. Wang
Yes, flock(1) can do the right job but personally I don't like the way a command is invoked by flock. :) And flock can only run external commands, it cannot do with things like bash builtins or functions. On Fri, Apr 16, 2010 at 12:04 AM, Eric Blake wrote: > On 04/15/2010 08:28 AM, Clark J. Wa

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Bob Proulx
Eric Blake wrote: > Clark J. Wang wrote: > > In C code I can use lockf(), flock(), semaphore and mutex for locking / > > unlocking. Can bash provide some similar mechanisms? > > man 1 flock > > If necessary, you may need to install: > ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/ There is

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Jan Schampera
Clark J. Wang schrieb: > In C code I can use lockf(), flock(), semaphore and mutex for locking / > unlocking. Can bash provide some similar mechanisms? > For simple things, which don't need to be 1000% rocksolid, you can use atomic operations like mkdir or noclobbered redirection for mutex purpos

Re: Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Eric Blake
On 04/15/2010 08:28 AM, Clark J. Wang wrote: > In C code I can use lockf(), flock(), semaphore and mutex for locking / > unlocking. Can bash provide some similar mechanisms? man 1 flock If necessary, you may need to install: ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/ -- Eric Blake eb

Re: Undocumented usage of printf?

2010-04-15 Thread Jan Schampera
Clark J. Wang schrieb: > I saw a printf usage from a Linux forum's post: > > # printf "%d\n" "'a" > 97 > # > > It's really cool but I found no info in bash's manual. Are there any other > undocumented interesting features? :) > I "documented" it, though I don't remember where I first heard abou

Re: Strange behavior of IFS?

2010-04-15 Thread Marc Herbert
Le 15/04/2010 14:58, Clark J. Wang a écrit : > I don't understand why the $string was still splitted into words since > it's double quoted. Anyone can give a reasonable explanation? set -x is often very good at giving explanations. Try this: sh -x foo.sh

Re: Undocumented usage of printf?

2010-04-15 Thread Eric Blake
On 04/15/2010 08:21 AM, Clark J. Wang wrote: > I saw a printf usage from a Linux forum's post: > > # printf "%d\n" "'a" > 97 > # POSIX requires this behavior, so you could claim that this serves as documentation: http://www.opengroup.org/onlinepubs/9699919799/utilities/printf.html "If the leadin

Feature request: Can bash provide some mechanism for locking/unlocking?

2010-04-15 Thread Clark J. Wang
In C code I can use lockf(), flock(), semaphore and mutex for locking / unlocking. Can bash provide some similar mechanisms?

Undocumented usage of printf?

2010-04-15 Thread Clark J. Wang
I saw a printf usage from a Linux forum's post: # printf "%d\n" "'a" 97 # It's really cool but I found no info in bash's manual. Are there any other undocumented interesting features? :)

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: Strange behavior of IFS?

2010-04-15 Thread Andreas Schwab
"Clark J. Wang" writes: > Look at following result: > > # 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 quoted.

Re: Strange behavior of IFS?

2010-04-15 Thread Clark J. Wang
I see. Thank you. On Thu, Apr 15, 2010 at 10:05 PM, Greg Wooledge wrote: > 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 >> # >>

Strange behavior of IFS?

2010-04-15 Thread Clark J. Wang
Look at following result: # 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 quoted. Anyone can give a reasonable explanation? -Clark

bash-4.1.5 crashes when trying to edit multiline command in vi mode

2010-04-15 Thread Roman Rakus
In bash-4.1 patchlevel 5 (probably all older versions) crashes. Reproducer: 1. set -o vi #set ups vi command line editing 2. type the following command as seen, but do not hit enter at last one for i in `ls` do echo $i done 3.After typeing done (but not enter), hit escape 4.type the letter v to