From: Maksim Otstavnov <maksim@otstavnov.com>
To: community@lists.altlinux.org
Subject: Re: [Comm] sh - bash
Date: Sun, 15 Oct 2006 14:55:03 +0400
Message-ID: <1242923031.20061015145503@otstavnov.com> (raw)
In-Reply-To: <20061015072634.GA7677@procyon.home>
Hello Sergey,
Sunday, October 15, 2006, 11:26:34 AM, you wrote:
SV> Правда, в стандарте есть одна проблема: там написано, что $(($x) и
SV> $((x)) должны работать одинаково, но возможность использовать
SV> переменные без $ в произвольных выражениях явно не прописана;
Так а второе из первого не следует. Я бы исходил из того, что такой
возможности нет.
SV> в результате существуют варианты /bin/sh, для которых заявлена
SV> совместимость с POSIX, но выражения вида $((A+B)) там не работают.
SV> Использование же конструкций вида $(($A+$B)) потенциально опасно,
SV> если переменные могут содержать непроверенные данные, не являющися
SV> целыми числами.
А чем бы помогло " $((A+B))"?
Кстати, и для раскрытия одной одвускобленной переменной написано, что
"*If the shell variable x contains a value that forms a valid integer
constant*, then the arithmetic expansions "$((x))" and "$(($x))" shall
return the same value" (Ibid., 2.3.6).
Не вполне понятно, как должна вести себя оболочка при нецелом или
нечисловом значении x; вполне возможно, что последнее предложение в
следующем за процитированным абзаце ("If the expression is invalid,
the expansion fails and the shell shall write a message to standard
error indicating the failure") просто забили отбить абзацем, и оно
относится к любому арифметическому раскрытию, а не только к случаям
поддержки нестандартных операций или иных типов переменных, о которых
говорится в сем абзаце.
Я, по крайней мере, столкнувшись некоторое время назад с этим
вопросом, понял это так: и "$((x))", и "$(($x))" при неподдерживаемом
арифметическом типе x или нечисловом x _должны_ (SHALL) вызывать
ошибку раскрытия. Есть другие идеи?
PS: А опечаток-то в тексте 2004 г.... :(
--
-- Maksim
next prev parent reply other threads:[~2006-10-15 10:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-14 21:57 Artem Zolochevskiy
2006-10-14 22:27 ` Alexey Rusakov
2006-10-15 5:41 ` Artem Zolochevskiy
2006-10-15 6:13 ` Alexey Rusakov
2006-10-15 8:41 ` Andrey Rahmatullin
2006-10-15 8:56 ` Artem Zolochevskiy
2006-10-15 9:03 ` Andrey Rahmatullin
2006-10-14 22:50 ` Pavel Usischev
2006-10-15 5:53 ` Artem Zolochevskiy
2006-10-15 5:57 ` Artem Zolochevskiy
2006-10-15 7:26 ` Sergey Vlasov
2006-10-15 7:43 ` Artem Zolochevskiy
2006-10-15 11:31 ` Dmitry V. Levin
2006-10-18 12:01 ` Fr. Br. George
2006-10-15 17:55 ` [Comm] heirloom toolchest Michael Shigorin
2006-10-15 10:55 ` Maksim Otstavnov [this message]
2006-10-15 17:52 ` [Comm] sh - bash Michael Shigorin
2006-10-15 17:48 ` Michael Shigorin
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=1242923031.20061015145503@otstavnov.com \
--to=maksim@otstavnov.com \
--cc=community@lists.altlinux.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
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git