From: "anonymous4feedback@outlook.com" <anonymous4feedback@outlook.com>
To: unlisted-recipients:; (no To-header on input)
Cc: "dash@vger.kernel.org" <dash@vger.kernel.org>
Subject: 回复: Bug in dash: Incorrect behaviour of $LINENO in function
Date: Sat, 14 Jan 2023 10:55:39 +0000 [thread overview]
Message-ID: <PS2PR03MB38306209EFE7E00A8B49CE9F92C39@PS2PR03MB3830.apcprd03.prod.outlook.com> (raw)
Sorry I didn't explain this clearly, and I made some wrong assumption in the first email.
I made another simpler test
# line 1 is empty
# line 2 is empty
foo(){ # line 2
echo $LINENO; } # line 3
foo # line 4
dash prints 2, (line number in function, counting from 1)
bash and ksh prints 4, (line number in whole script)
and zsh prints 1 (line number in function, counting from 0)
More test moving the lines around confirms the guess in parens.
Can I say that none of these is wrong because there is no standard about this?
发件人: Marc Chantreux <mc@unistra.fr>
发送时间: 2023年1月14日 17:39
收件人: anonymous4feedback@outlook.com <anonymous4feedback@outlook.com>
抄送: dash@vger.kernel.org <dash@vger.kernel.org>
主题: Re: Bug in dash: Incorrect behaviour of $LINENO in function
hello,
> It seems dash stores the line number of the parameter substitution and the line number of the function definition
which is what we expect from a variable expansion. what you need here
is an alias because it works like a minimal but dynamic preprocessor
those are the tricks about aliases:
* they really act as a preprocessor so
alias warn='>&2 echo here at $LINENO'
f() warn first
alias warn='>&2 echo another message at $LINENO'
g() warn last
f;g
# does
here at 1 first
another message at 1 last
* interpolation comes first so
entering() {
echo entering "$@"
"$@"
}
f() echo doing things in functions
alias damn='echo oops ...'
entering f
entering damn
entering f
doing things in functions
entering damn
/home/mc/src/vendor/dash/src/dash: 3: damn: not found
conclusion:
* use functions as long as you can
* in this case, you can't. your solution is
alias warn='>&2 echo here at $LINENO'
HTH,
Marc Chantreux
next reply other threads:[~2023-01-14 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-14 10:55 anonymous4feedback [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-01-14 5:30 Bug in dash: Incorrect behaviour of $LINENO in function anonymous4feedback
2023-01-14 9:39 ` Marc Chantreux
2023-01-14 10:57 ` 回复: " anonymous4feedback
2023-01-14 11:10 ` Harald van Dijk
2023-01-14 13:52 ` Marc Chantreux
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=PS2PR03MB38306209EFE7E00A8B49CE9F92C39@PS2PR03MB3830.apcprd03.prod.outlook.com \
--to=anonymous4feedback@outlook.com \
--cc=dash@vger.kernel.org \
/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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).