From: Sergey Vlasov <vsu@altlinux.ru> To: community@lists.altlinux.org Subject: Re: [Comm] sh - bash Date: Sun, 15 Oct 2006 11:26:34 +0400 Message-ID: <20061015072634.GA7677@procyon.home> (raw) In-Reply-To: <egsifm$hdr$1@sea.gmane.org> [-- Attachment #1: Type: text/plain, Size: 2027 bytes --] On Sun, Oct 15, 2006 at 08:53:03AM +0300, Artem Zolochevskiy wrote: > Pavel Usischev wrote: > >> Собственно вопрос относительно написания скриптов > >> Отчего же тогда вижу везде #!/bin/sh (в стартовых сценариях итп) - если > >> этот sh такой старый и неумека? > > > > Как раз для переносимости скрипта. В ALT /bin/sh -- это особый вариант > > bash, в других системах это вполне может быть другой шелл, а bash вообще > > может отсутствовать. > > Так вот и я так думал, а получается, что нет. Ибо в альтовских скриптах > (благодаря тому, что в альт sh это тот же bash) повсеместно используются > фичи, кот в "оригинальном" sh не прокатят. Получается о совместимости тут > речи нет. В Debian /bin/sh может ссылаться на любой POSIX compatible shell: The standard shell interpreter /bin/sh can be a symbolic link to any POSIX compatible shell, if echo -n does not generate a newline. http://www.debian.org/doc/debian-policy/ch-files.html#s-scripts У нас пока такого нет, но всё равно лучше в скриптах, где написано #!/bin/sh, не использовать возможности, специфические для bash. > альтовский sh: > sh-3.1$ A=5 > sh-3.1$ B=6 > sh-3.1$ C=$(($A+$B)) > sh-3.1$ echo $C > 11 > sh-3.1$ > > а по идее в sh это не должно прокатывать > heirloom-sh: > $ A=5 > $ B=6 > $ C=$(($A+$B)) > syntax error: `C=$' unexpected > $ Это arithmetic expansion, который вообще-то входит в последний вариант спецификации POSIX sh: http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04 Правда, в стандарте есть одна проблема: там написано, что $(($x) и $((x)) должны работать одинаково, но возможность использовать переменные без $ в произвольных выражениях явно не прописана; в результате существуют варианты /bin/sh, для которых заявлена совместимость с POSIX, но выражения вида $((A+B)) там не работают. Использование же конструкций вида $(($A+$B)) потенциально опасно, если переменные могут содержать непроверенные данные, не являющися целыми числами. [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2006-10-15 7:26 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 [this message] 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 ` [Comm] sh - bash Maksim Otstavnov 2006-10-15 17:52 ` 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=20061015072634.GA7677@procyon.home \ --to=vsu@altlinux.ru \ --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