ALT Linux Community general discussions
 help / color / mirror / Atom feed
* [Comm] арифметика в bash
@ 2005-06-19 14:03 Andrei Lomov
  2005-06-19 14:53 ` Valery V. Inozemtsev
  0 siblings, 1 reply; 4+ messages in thread
From: Andrei Lomov @ 2005-06-19 14:03 UTC (permalink / raw)
  To: community


Не соображу, как в bash превратить числовую строку в integer.

Нужно имена файлов 
001 002 003 

превратить в 
002 004 006
(умножить на два)


ТО есть сделать нечто типа
for i in *
    do  echo "$i"; echo $i+$i
   done

только операцию "+" сделать арифметической, а не текстовой.

Спасибо заранее за наводку.

-- 
Всего доброго,
А.Л.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Comm] арифметика в bash
  2005-06-19 14:03 [Comm] арифметика в bash Andrei Lomov
@ 2005-06-19 14:53 ` Valery V. Inozemtsev
  2005-06-19 15:11   ` [Comm] Re: арифметика в bash [JT] Andrei Lomov
  0 siblings, 1 reply; 4+ messages in thread
From: Valery V. Inozemtsev @ 2005-06-19 14:53 UTC (permalink / raw)
  To: community

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]

В сообщении от 19 Июнь 2005 18:03 Andrei Lomov написал(a):
> Не соображу, как в bash превратить числовую строку в integer.
>
> Нужно имена файлов
> 001 002 003
>
> превратить в
> 002 004 006
> (умножить на два)
>
>
> ТО есть сделать нечто типа
> for i in *
>     do  echo "$i"; echo $i+$i
>    done
>
> только операцию "+" сделать арифметической, а не текстовой.
$ for i in 001 002 003 ;do echo $(($i + $i)); done
$ for i in 001 002 003 ;do echo $(($i * 2)); done
-- 
Valery V. Inozemtsev

[-- Attachment #2: Type: application/pgp-signature, Size: 190 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Comm] Re: арифметика в bash [JT]
  2005-06-19 14:53 ` Valery V. Inozemtsev
@ 2005-06-19 15:11   ` Andrei Lomov
  2005-06-19 21:36     ` Vitaly Lipatov
  0 siblings, 1 reply; 4+ messages in thread
From: Andrei Lomov @ 2005-06-19 15:11 UTC (permalink / raw)
  To: community

Valery V. Inozemtsev wrote:

> $ for i in 001 002 003 ;do echo $(($i + $i)); done
> $ for i in 001 002 003 ;do echo $(($i * 2)); done

Спасибо. 
Честно говоря, долго смотрел на соответствующий кусок man bash:

 ((выражение))
   Выражение вычисляется в  соответствии с правилами, описанными
   ниже  в  разделе  "ВЫЧИСЛЕНИЕ  АРИФМЕТИЧЕСКИХ  ВЫРАЖЕНИЙ".  Если
   выражение имеет ненулевое значение, статус возврата равен  0;  в
   противном  случае  - 1.

Понял так, что кроме статуса, ничего путного не возвращается :(
Даже проверить мысли не возникло. 
Вот и пиши после этого маны для таких как я :)

-- 
Всего доброго,
А.Л.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Comm] Re: арифметика в bash [JT]
  2005-06-19 15:11   ` [Comm] Re: арифметика в bash [JT] Andrei Lomov
@ 2005-06-19 21:36     ` Vitaly Lipatov
  0 siblings, 0 replies; 4+ messages in thread
From: Vitaly Lipatov @ 2005-06-19 21:36 UTC (permalink / raw)
  To: community

On Sunday 19 June 2005 19:11, Andrei Lomov wrote:
> Понял так, что кроме статуса, ничего путного не возвращается
$ echo $((2+2))
4

> :( Даже проверить мысли не возникло.
А зря. Кроме статуса, результат вычисления можно получить в 
выводе.
> Вот и пиши после этого маны для таких как я :)

-- 
Lav
Виталий Липатов
Санкт-Петербург
GNU! ALT Linux Team! WINE! LaTeX! LyX!


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-06-19 21:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-19 14:03 [Comm] арифметика в bash Andrei Lomov
2005-06-19 14:53 ` Valery V. Inozemtsev
2005-06-19 15:11   ` [Comm] Re: арифметика в bash [JT] Andrei Lomov
2005-06-19 21:36     ` Vitaly Lipatov

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