Re: bash manual/info lacks examples
On Thu, Aug 05, 1999 at 10:10:30AM +0200, Andreas Tille wrote:
> On Thu, 5 Aug 1999, Mirek Kwasniak wrote:
>
> > 1) For builtins bash has also help:
> >
> > $ help let | less
> >
> > 2) Usage of man (my pager is `less')
> >
> >
> > 3) Usage of info
> Please don't understand me wrong. I *found* the text where
> the description of let is documented. But what do I have to
> type if I want to increase a shell variable? The syntax of
> "arithmetic expression" remains unclear and an example, how
> to do
>
> a = $b + $c * $d
> and
> a = ($b + $c) * $d
^ ^ ^ ^ ^ ^
-------------------------------- you can't use space whitout quoting
$ b=2;c=3;d=7
$ a=$b+$c*$d;echo $a
2+3*7
$ let a=$b+$c*$d;echo $a
23
$ let a=$b+($c*$d);echo $a
bash: syntax error near unexpected token `a=$b+($'
$ let a=$b+\($c*$d\);echo $a
23
$ a=\($b+$c\)*$d;echo $a
(2+3)*7
$ let a=\($b+$c\)*$d;echo $a
35
$ let a="($b+$c)*$d";echo $a
35
$ let a='($b+$c)*$d';echo $a
bash: let: a=($b+$c)*$d: syntax error: operand expected (error token is "$b+$c)*$d")
I'm little confused but I'm not guru in bash (I'll go to the man again).
$ let a="( $b + $c ) * $d";echo $a
35
Ok we can use spaces in this manner.
Alternatives for `let a=....' are:
$ ((a=($b+$c)*$d));echo $a
35
$ a=$(((b+c)*d));echo $a
35
$ a=$[(b+c)*d];echo $a
35
Where I found '$[ ... ]' I don't know :(. I usually use this construction :)
Mirek
Reply to: