From: Ken Smith <ken@smith.net>
To: zsh-workers@sunsite.auc.dk
Subject: Unexpected Results/Heisenbug
Date: Thu, 11 May 2000 02:48:54 +0200 [thread overview]
Message-ID: <391A0376.F6A947F5@smith.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 430 bytes --]
Attached is a script which surprised me when I tested it. When run with
DEBUG=0, the output is as I would expect. When run with DEBUG=1, the
for loop sets ${each} to "continue:" after the debugging code executes.
Is this a problem with my nubile scripting skills or does this signify a
problem with zsh? Please cc responses to ken at smith.net as I am not a
subscriber of the zsh-workers mailing list.
Thank you for any tips.
[-- Attachment #2: zsh_for_test --]
[-- Type: text/plain, Size: 1355 bytes --]
#!/bin/zsh
DEBUG=1
function debugging
{
[[ ${+DEBUG} == 1 && ${DEBUG} == 1 ]]
}
function format_output
{
function arg_len
{
echo $1 | wc -c
}
heading_separator=": "
prefix=${1}${heading_separator}
prefix_len=`arg_len ${prefix}`
if [[ ${+COLUMNS} == 1 ]]; then
columns=${COLUMNS}
else
columns=80
fi
terminal_position=0
first_argument=1
just_wrote_prefix=0
for each in $*; do
if [[ ${first_argument} == 1 ]]; then
first_argument=0
continue
fi
if [[ ${terminal_position} == 0 ]]; then
echo -n ${prefix}
just_wrote_prefix=1
fi
token_len=`arg_len ${each}`
((terminal_position += token_len + 1))
if [[ ${terminal_position} > ${columns} ]]; then
# If we just wrote the prefix, then we
# have to write this token where it stands
# even though it will wrap.
if [[ ${just_wrote_prefix} == 1 ]]; then
echo ${each}
just_wrote_prefix=0
((terminal_position = 0))
else
echo -n "\n${prefix}${each} "
((terminal_position =
prefix_len + token_len))
just_wrote_prefix=0
fi
else
echo -n "${each} "
just_wrote_prefix=0
fi
done
echo
}
if debugging; then
format_output DEBUG Executing \"${0} ${*}\"
fi
for each in test1 test2 test3; do
echo "***each=${each}"
if debugging; then
format_output DEBUG press enter to continue:
read
fi
echo "***each=${each}"
done
next reply other threads:[~2000-05-11 0:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-11 0:48 Ken Smith [this message]
2000-05-11 4:04 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=391A0376.F6A947F5@smith.net \
--to=ken@smith.net \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).