osdir.com
mailing list archive
Mozy Online Backup: 2GB Free. Automatic. Secure.

Subject: AND list "command1 && command2" doesn't work as expected - msg#00169

List: shells.bash.bugs

Date: Prev Next Index Thread: Prev Next Index
From: yafrank@xxxxxxx
To: bug-bash@xxxxxxx
Subject: AND list "command1 && command2" doesn't work
as expected

Configuration Information [Automatically generated, do
not change]:
Machine: i386
OS: linux-gnu
Compiler: i386-redhat-linux-gcc
Compilation CFLAGS: -DPROGRAM='bash'
-DCONF_HOSTTYPE='i386'
-DCONF_OSTYPE='linux-gnu'
-DCONF_MACHTYPE='i386-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H -I.
-I. -I./include
-I./lib -D_FILE_OFFSET_BITS=64 -O2 -g -pipe
-march=i386 -mcpu=i686
uname output: Linux twinhead 2.4.27-lck1-bsdc #1
日 10月 3 16:05:43 CST
2004 i686 i686 i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
The bash script "Example 26-14. Emulating a push-down
stack" from
"http://www.tldp.org/LDP/abs/html/arrays.html"; works
fine and there is
an excercise to modify the code to support multiple
element push and
pop. The homework I did works fine until I took for
granted the logical
equivalence AND list should give the same result.
Detail follows:
*********************************************************
#!/bin/bash

BP=100
SP=$BP
LOW_LIMIT=0

DATA=

declare -a stack

push () {
for (( i=1; i<=$#; i++)); do
if [ "$SP" -gt "$LOW_LIMIT" ]; then
stack[SP--]="${!i}"
else
echo "Stack full"
break
fi
done
}

pop () {
count=${1:-1}
DATA=""

for ((i=0; i<count; i++)); do

if [ "$SP" -lt "$BP" ]; then
DATA="$DATA ${stack[++SP]}"
else
echo "Stack empty"
break
fi

# Alter the above "if...else...fi" clause using its
logical equivalent
#+ [ "$SP" -lt "$BP" ] && DATA="$DATA
${stack[++SP]}" || \
#+ { echo "Stack empty"; break; }
#+ won't give the same result. This is not expected.

done
}

status () {
echo "-------------------------------------"
echo "REPORT"
echo "Stack Pointer = $SP"
echo "Just popped \""${DATA# }"\" off the stack."
echo "-------------------------------------"
}

pop # empty stack popup
status # If AND list used in pop(), reports
"SP=101" here

echo
push garbage
pop
status

v1=23; v2=skiddo; v3=final

echo
push $v1 $v2 $v3
status
pop
status
pop 2
status

exit 0
*********************************************************
The bash manual says that for "command1 && command2",
"command2 is executed if, and only if, command1
returns an
exit status of zero." It seems conflict here to the
first
status report "SP=101", which means SP increased by
one even
if "[ "$SP" -lt "$BP" ]" returns non zero when pop an
empty
stack. Is there anything wrong here?

Repeat-By:
Everytime the "if...else...fi" in pop() replaced by
logical equivalence AND/OR list as in the comment.



Regards

---Frank Wang


________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: <<IFS=: foo=a:b:; cmd $messageInfo = array( "subject" => "Re: <<IFS=: foo=a:b:; cmd $foo>> documented", "msgnum" => "00168", "listTitle" => "shells.bash.bugs", "author" => "Stephane CHAZELAS", "dateGMT" => "Wed Oct 13 07:20:26 GMT 2004", "dateIndex" => "index.html#00168", "threadIndex" => "threads.html#00168", "prevMsg" => "msg00167.html", "prevMsgSubject" => "VIRUS IN MAIL TO jn@xxxxxxxxxxxxxx", "prevMsgT" => "msg00158.html", "prevMsgTSubject" => "Re: <<IFS=: foo=a:b:; cmd $foo>> documented", "nextMsg" => "msg00169.html", "nextMsgSubject" => "AND list "command1 && command2" doesn't work as expected", "nextMsgT" => "msg00155.html", "nextMsgTSubject" => "AWARD NOTIFICATION", "allLists" => "/~mhonarc/archives/html" );>> documented

On Tue, Oct 12, 2004 at 09:37:50AM -0400, Chet Ramey wrote: [...] > In bash, and POSIX.2, and the other listed shells, trailing IFS characters > never result in a separate field. > > They're field delimiters, so they're treated as field terminators, which is > not necessarily the same as field separators. A trailing IFS character > delimits the final field. [...] Hi Chet, Yes, I understand that. My point was that it is not clearly documented. And one would expect the zsh/pdksh/awk/perl -na/cut -f/execvp behavior as it is called an "internal field *separator*". The beginning and end of the string can also be seen as natural delimiters. I could not find in the SUSv3 where it is specified that a trailing IFS non-white character should be discarded (or seen as the end of the last field and not the beginning of an empty other one terminated by the end of the string). Or is it in the unsaid definition of "delimiter"? regards, Stephane

Next Message by Date: click to view message preview

Remember, We will fully Train you for free.

Tom with an update, ...here is the Secret: If you decide to make 6000 US.dollars in your first 30 days! Part Time! - ..just read on... What's the best Product without being able to produce your Unique and Own Leads? Here you will be Trained on USA's turnkey Marketing Machine No 1 ! We train - We support - We even sell for YOU! ..what's the Trick? It's the way you TREAT people! Succeed by Helping others to become Huge! Receive all Details by emailing to Succeed@xxxxxxxxxxxx with "Succeed, Please!" in the header. Also list your Phone number in case you wish to talk to me personally. Pelase D-O N-O-T click the Reply key to this email though! Thanks, to your success, Tom Sanders - LG.Tymes to get off this list, just email to Gone@xxxxxxxxxxxx with "Off Server" in the sub-ject. Thanks.

Previous Message by Thread: click to view message preview

VIRUS IN MAIL TO jn@xxxxxxxxxxxxxx

V I R U S A L E R T Our virus scanner has found a virus in an email addressed to "jn@xxxxxxxxxxxxxx". The headers of the email indicate that it may have come from you. Some email viruses use forged headers which means that the virus might have not have come from your system. It is also possible that a virus has sent the email from your system and you are not aware of it. You should take the time to check your system for viruses using an up to date virus scanner. For your reference, here are the headers from your email: ------------------------- BEGIN HEADERS ----------------------------- Received: (qmail 32550 invoked from network); 13 Oct 2004 07:08:21 -0000 Received: from unknown (HELO it.swin.edu.au) (164.100.40.27) by venus.it.swin.edu.au with SMTP; 13 Oct 2004 07:08:21 -0000 From: bug-bash@xxxxxxx To: jn@xxxxxxxxxxxxxx Subject: Hello Date: Wed, 13 Oct 2004 12:38:22 +0530 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0016----=_NextPart_000_0016" X-Priority: 3 X-MSMail-Priority: Normal X-AntiVirus: scanned for viruses by AMaViS -------------------------- END HEADERS ------------------------------

Next Message by Thread: click to view message preview

Re: AND list "command1 && command2" doesn't work as expected

> Machine Type: i386-redhat-linux-gnu > > Bash Version: 2.05b > Patch Level: 0 > Release Status: release > > Description: > The bash script "Example 26-14. Emulating a push-down stack" from > "http://www.tldp.org/LDP/abs/html/arrays.html" works fine and there is > an excercise to modify the code to support multiple element push and > pop. The homework I did works fine until I took for granted the logical > equivalence AND list should give the same result. Detail follows: I can't reproduce any problem using bash-2.05b or bash-3.0.13 (patched). I get the same results no matter which version or which construct I use. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ( ``Discere est Dolere'' -- chet ) Live...Laugh...Love Chet Ramey, ITS, CWRU chet@xxxxxxxxxxx http://tiswww.tis.cwru.edu/~chet/
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by