Re: logical XOR

2007-06-29 Thread Robert Millan [ackstorm]
On Thu, Jun 28, 2007 at 06:58:25PM -0400, Chet Ramey wrote:
> ackstorm wrote:
> > Configuration Information [Automatically generated, do not change]:
> > Machine: i486
> > OS: linux-gnu
> > Compiler: gcc
> > Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
> > -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
> > -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
> > -DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
> > uname output: Linux acklap03 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 
> > 2007 i686 GNU/Linux
> > Machine Type: i486-pc-linux-gnu
> > 
> > Bash Version: 3.1
> > Patch Level: 17
> > Release Status: release
> > 
> > Description:
> > There's bitwise AND and bitwise OR, and logical AND and logical OR, but
> > for XOR there's only the bitwise version.  Would be nice if the logical
> > XOR would also be present (^^).
> 
> (!a) != (!b)
> 
> should work acceptably for the situations such an operator would be used.

I'm not sure what you mean.  The following:

(true && ! false) || (false && ! true)
echo $?

works, whereas the following:

(! true) != (! false)
echo $?

shows syntax error.

Is there any way to avoid redundancy in the shell script that needs this?  The
code in question is already quite complex, so adding this redundancy makes it
less readable.

> The reason it's not there is because it's not in C.

Because of performance?

-- 
Robert Millan


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: logical XOR

2007-06-29 Thread Stephane Chazelas
On Fri, Jun 29, 2007 at 10:21:01AM +0200, Robert Millan [ackstorm] wrote:
[...]
> > >   There's bitwise AND and bitwise OR, and logical AND and logical OR, but
> > >   for XOR there's only the bitwise version.  Would be nice if the logical
> > >   XOR would also be present (^^).
> > 
> > (!a) != (!b)
> > 
> > should work acceptably for the situations such an operator would be used.
> 
> I'm not sure what you mean.  The following:
> 
>   (true && ! false) || (false && ! true)
>   echo $?
> 
> works, whereas the following:
> 
>   (! true) != (! false)
>   echo $?
> 
> shows syntax error.
> 
> Is there any way to avoid redundancy in the shell script that needs this?  The
> code in question is already quite complex, so adding this redundancy makes it
> less readable.
[...]

Do you mean that for instance, you'd like a third command to be
executed if either but not both of two commands succeed?

cmd1; a=$?
cmd2; b=$?
(( !a != !b )) && cmd3

should do.

-- 
Stéphane


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: logical XOR

2007-06-29 Thread Robert Millan [ackstorm]
On Fri, Jun 29, 2007 at 10:16:18AM +0100, Stephane Chazelas wrote:
> 
> Do you mean that for instance, you'd like a third command to be
> executed if either but not both of two commands succeed?
> 
> cmd1; a=$?
> cmd2; b=$?
> (( !a != !b )) && cmd3
> 
> should do.

Thank you, that works.  Although I think ^^ would be more intuitive.  Let me
know if you want a patch for that.

-- 
Robert Millan


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: logical XOR

2007-06-29 Thread Andreas Schwab
"Robert Millan [ackstorm]" <[EMAIL PROTECTED]> writes:

> I'm not sure what you mean.  The following:
>
>   (true && ! false) || (false && ! true)
>   echo $?
>
> works, whereas the following:
>
>   (! true) != (! false)
>   echo $?
>
> shows syntax error.

true and false are not numbers.  The OP was talking about expression
evaluation.

Andreas.

-- 
Andreas Schwab, SuSE Labs, [EMAIL PROTECTED]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: bash: no job control in this shell

2007-06-29 Thread JimK



Bob Proulx wrote:
> 
> 
>>Does this java applet set up a master-slave pty for bash's input and
>>output?  This is what the 'expect' program and similar usually do.
> 
> Yep, I drop down into C to use openpty() to set up the master/slave and
> pass the
> file IDs back up into java.I Use input/output streams on the master side
> to interact with the applet
> and associate the slave FD to the stdin/stdout/stderr of bash which I
> invoe with -i -s
> 
>>You would probably need "q\n" in order to get the data flushed to the
>>subprocess.  This is probably a stdio buffering issue.  When the stdio
>>library determines that the output is not a tty then the output is
>>buffered into large blocks for performance reasons.  If the output is
>>a tty then buffering is disabled.  (I can't remember if buffering is
>>off or line buffered when the output is a tty.)
> 
> Is this all still true even if I am already using a master/slave? All
> other commands (so far) and even vi work fine, so I have not had to
> interject anything to force data to flow.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/bash%3A-no-job-control-in-this-shell-tf3995540.html#a11359334
Sent from the Gnu - Bash mailing list archive at Nabble.com.



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: logical XOR

2007-06-29 Thread Stephane Chazelas
On Fri, Jun 29, 2007 at 12:08:22PM +0200, Robert Millan [ackstorm] wrote:
> On Fri, Jun 29, 2007 at 10:16:18AM +0100, Stephane Chazelas wrote:
> > 
> > Do you mean that for instance, you'd like a third command to be
> > executed if either but not both of two commands succeed?
> > 
> > cmd1; a=$?
> > cmd2; b=$?
> > (( !a != !b )) && cmd3
> > 
> > should do.
> 
> Thank you, that works.  Although I think ^^ would be more intuitive.  Let me
> know if you want a patch for that.
[...]

You could do something like:

xor() {
  previous_status=$?
  "$@"
  return "$((!$previous_status == !$?))"
}

cmd1; xor cmd2 && cmd3

-- 
Stéphane


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Evaluate expression every time directory changes

2007-06-29 Thread bash_user

That is correct.  
I would like to understand what triggers the shell to re-evaluate
PROMPT_COMMAND every time 
directory / clock change occur. 
 
THANKS FOR REPLY!



Dave Rutherford-2 wrote:
> 
> On 6/28/07, bash_user <[EMAIL PROTECTED]> wrote:
>> Lets say I would like to update environment variable based on ${PWD}
>> should I clobber my prompt generation routine or there is a better way.
> 
> Something like this?
> 
> PROMPT_COMMAND='eval NEWPWD="\$PWD"'
> 
> Dave
> 
> 
> ___
> Bug-bash mailing list
> Bug-bash@gnu.org
> http://lists.gnu.org/mailman/listinfo/bug-bash
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Evaluate-expression-every-time-directory-changes-tf3996206.html#a11362032
Sent from the Gnu - Bash mailing list archive at Nabble.com.



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Evaluate expression every time directory changes

2007-06-29 Thread bash_user

Hello, 

Lets say I would like to update environment variable based on ${PWD}
should I clobber my prompt generation routine or there is a better way. 

THANKS!
  Nashi
-- 
View this message in context: 
http://www.nabble.com/Evaluate-expression-every-time-directory-changes-tf3996206.html#a11349158
Sent from the Gnu - Bash mailing list archive at Nabble.com.



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Evaluate expression every time directory changes

2007-06-29 Thread Dave Rutherford

On 6/28/07, bash_user <[EMAIL PROTECTED]> wrote:

Lets say I would like to update environment variable based on ${PWD}
should I clobber my prompt generation routine or there is a better way.


Something like this?

PROMPT_COMMAND='eval NEWPWD="\$PWD"'

Dave


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: Evaluate expression every time directory changes

2007-06-29 Thread Bob Proulx
bash_user wrote:
> That is correct.  
> I would like to understand what triggers the shell to re-evaluate
> PROMPT_COMMAND every time 
> directory / clock change occur. 

The documentation for bash says:

   PROMPT_COMMAND
  If set, the value is executed as a command prior to issuing each
  primary prompt.

It is not triggered when the current working directory changes.  It is
triggered every time a prompt is printed.  This is such a small amount
of cpu time that it is probably not worth the effort to make it only
happen when the directory changes.

Bob


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: logical XOR

2007-06-29 Thread Chet Ramey
Robert Millan [ackstorm] wrote:

>>> There's bitwise AND and bitwise OR, and logical AND and logical OR, but
>>> for XOR there's only the bitwise version.  Would be nice if the logical
>>> XOR would also be present (^^).
>> (!a) != (!b)
>>
>> should work acceptably for the situations such an operator would be used.
> 
> I'm not sure what you mean.  The following:
> 
>   (true && ! false) || (false && ! true)
>   echo $?
> 
> works, whereas the following:
> 
>   (! true) != (! false)
>   echo $?
> 
> shows syntax error.

That really doesn't have anything to do with the issue.  The original
question concerned the arithmetic operators accepted by the expression
evaluator, not the shell language.

>> The reason it's not there is because it's not in C.
> 
> Because of performance?

Because bash implements a subset of C's arithmetic language (with one
exception), and C doesn't have a logical XOR operator.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash