Re: bash manual/info lacks examples - addendum
Hi again,
I read your mail again. I answered in previous message about metods I use
for finding information.
Your question is about lacking examples either. You are right. Man- and
info-pages assume some basic knowledge about computer, os (operating
system), programming and technical documentation. They are sufficient for
me.
I your case (bash let semantics) I try provide some examples.
Man says:
let arg [arg ...]
Each arg is an arithmetic expression to be evalu
ated (see ARITHMETIC EVALUATION). If the last arg
evaluates to 0, let returns 1; 0 is returned other
wise.
This assumes your knowledge abot how args are separated (hint: IFS
variable) and about what and for what is return value (this explained in
many places of manpage).
Now you need information about ARITHMETIC EVALUATION.
ARITHMETIC EVALUATION
The shell allows arithmetic expressions to be evaluated,
under certain circumstances (see the let builtin command
and Arithmetic Expansion). [...]
You must know here whatis "arithmetic expressions" and maybe find more info
opearators (they are here only listed.
Now some examples
$ let a=2
$ echo $a
2
$ let $a*2 && echo non-zero || echo zero
non-zero
$ let $a*0 && echo non-zero || echo zero
zero
$ let b=$a*$a c=$a+$b
$ echo a=$a b=$b c=$c
a=2 b=4 c=4
$ unset a
$ unset b
$ unset c
$ ( a=2; let a=$a+$a b=$a+$a; echo a=$a b=$b)
a=4 b=4
$ ( a=2; let a=$a+$a; let b=$a+$a; echo a=$a b=$b)
a=4 b=8
Tschuess
Mirek
Reply to: