ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Vladimir Karpinsky <vkarpinsky@mail.ru>
To: community@lists.altlinux.org
Subject: Re: [Comm] Арифметика в bash
Date: Thu, 17 Nov 2011 20:06:35 +0400
Message-ID: <4EC5310B.6090903@mail.ru> (raw)
In-Reply-To: <20111117155027.GA6399@atlas.home>

17.11.2011 19:50, Sergey Vlasov пишет:
> On Thu, Nov 17, 2011 at 11:51:09AM +0400, Vladimir Karpinsky wrote:
>> Уже некоторое время пытаюсь найти простое решение следующей
>> проблемы: нужно производить простейшие арифметические операции (как
>> правило + или -1 ;-)) с "юлианскими" днями года (date +%j).
>> Сложность заключается в том, что формат такой даты JJJ, т.е. первые
>> 99 дней года первая цифра 0, и bash считает это число восьмеричным,
>> со всеми вытекающими последствиями. Хочется заставить bash работать
>> с такими числами, как десятеричными, формат JJJ для результата
>> вычисления желательно также сохранить.
>
> Именно в bash поддерживается синтаксис вида BASE#NUMBER с явным
> указаним основания:
>
>    $ bash -c 'a=011; echo $((10#$a))'
>    11
>
> Нужно учитывать, что в POSIX sh такой синтаксис не поддерживается,
> поэтому в скриптах нужно явно указывать #!/bin/bash (использование
> #!/bin/sh в ALT пока не проявится в виде ошибок, но в некоторых
> дистрибутивах в роли /bin/sh может оказаться, например, dash).
>
> Выводить числа в нужном формате можно через printf '%03d' $n .

Спасибо! Где-то я похоже не там искал. Я, ведь, даже пытался 
форматированный вывод искать...

-- 
	С уважением,
		Владимир.


      reply	other threads:[~2011-11-17 16:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17  8:20   ` Константин Михайленко
2011-11-17  9:31     ` Vladimir Karpinsky
2011-11-17  9:35   ` Yura Kalinichenko
2011-11-17  9:50     ` Vladimir Karpinsky
2011-11-17  9:53       ` Vladimir Karpinsky
2011-11-17 15:50   ` Sergey Vlasov
2011-11-17 16:06     ` Vladimir Karpinsky [this message]

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=4EC5310B.6090903@mail.ru \
    --to=vkarpinsky@mail.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