bash manual/info lacks examples
Hello, every time I read the bash manual to get help I'm missing examples for the basic usage of a builtin. For instance I managed to write a simple shell script with a loop which increased a variable i = 0; while [ $i -lt $MAX ] ; do echo $i let ... done But I havn't my small loop script handy this time and wanted to know the syntax of let using `man bash` or `info bash`. I'm I stupid or what is the reason that I can't find out, how this expression after let has to be formed? It is the same with the other bash features. The manual is IMHO very abstract and gives less practical help. So I would like to suggest to beg the programmers to add some examples for better reading. By the way could someone please enlighten my how to form the expression. Kind regards Andreas.
Re: bash manual/info lacks examples
On Thu, Aug 05, 1999 at 08:49:31AM +0200, Andreas Tille wrote: Hello, every time I read the bash manual to get help I'm missing examples for the basic usage of a builtin. For instance I managed to write a simple shell script with a loop which increased a variable i = 0; while [ $i -lt $MAX ] ; do echo $i let ... done But I havn't my small loop script handy this time and wanted to know the syntax of let using `man bash` or `info bash`. I'm I stupid or what is the reason that I can't find out, how this expression after let has to be formed? 1) For builtins bash has also help: $ help let | less 2) Usage of man (my pager is `less') $ man bash /\let\ n n and I see 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. I go to top of manpage and issue new search: /ARITHMETIC EVALUATION and see detailed description. 3) Usage of info $ info bash ^s let ^ ^ ^---^-- here arre spaces ^s and I see `let' let EXPRESSION [EXPRESSION] The `let' builtin allows arithmetic to be performed on shell variables. Each EXPRESSION is evaluated according to the rules given below in *Note Shell Arithmetic::. If the last EXPRESSION evaluates to 0, `let' returns 1; otherwise 0 is returned. after that I go to topic Shell Arithmetic. Regards Mirek
Re: bash manual/info lacks examples
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 (because this demonstrates also braces in expresions which might be misinterpreted by the shell) would be really helpful. Kind regards Andreas.
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
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
Re: bash manual/info lacks examples - addendum
Thank you very much Mirek. Yes, I wanted to express, that the use of documentation is limited if there are no examples in it. In the case of `let` it was only my personal problem (which I would be able to solve by searching for my own old example at home ... or by asking you over the list :) ). I wanted to point out that fact which is a cruxial one if we want to build a user-friendly OS (if man pages could be user friendly at all. I consider them to be useful, but others don't). Kind regards Andreas.
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 (because this demonstrates also braces in expresions which might be misinterpreted by the shell) would be really helpful. bash shells can do: let a=$b+$c*$d let a=($b+$c)*$d but if you want to ensure compatibility with Bourne shells like ash, you should stick to: a=$(($b+$c*$d)) a=$((($b+$c)*$d)) HTH, Mike [Private mail welcome, but no need to CC: me on list replies.] hehe... the random sig hits again! -- Michael Merten --- E-Mail: [EMAIL PROTECTED] --- NRA Life Member -- http://www.nra.org --- Debian GNU/Linux Fan -- http://www.debian.org --- CenLA-LUG Founder -- http://www.angelfire.com/la2/cenlalug -- It's great to be smart 'cause then you know stuff.
Re: bash manual/info lacks examples
Says Mike: bash shells can do: let a=$b+$c*$d let a=($b+$c)*$d but if you want to ensure compatibility with Bourne shells like ash, you should stick to: a=$(($b+$c*$d)) a=$((($b+$c)*$d)) but if you want to ensure compatibility with Bourne shells like the Bourne shell :), you should stick to a=`expr $b + $c \* $d` a=`expr \( $b + $c \) \* $d` to complicate things, the spaces in the expression after `expr' are required. HTH, Eric -- E.L. Meijer ([EMAIL PROTECTED]) Eindhoven Univ. of Technology Lab. for Catalysis and Inorg. Chem. (SKA)
Re: bash manual/info lacks examples
On Thu, Aug 05, 1999 at 02:53:02PM +0200, E.L. Meijer (Eric) wrote: Says Mike: bash shells can do: let a=$b+$c*$d let a=($b+$c)*$d but if you want to ensure compatibility with Bourne shells like ash, you should stick to: a=$(($b+$c*$d)) a=$((($b+$c)*$d)) but if you want to ensure compatibility with Bourne shells like the Bourne shell :), you should stick to a=`expr $b + $c \* $d` a=`expr \( $b + $c \) \* $d` to complicate things, the spaces in the expression after `expr' are required. I stand corrected :) It's been a LONG time since I've use the authentic one-and-only Bourne shell. How many Bourne shell clones do we have floating around here these days? Mike [Private mail welcome, but no need to CC: me on list replies.] -- Michael Merten --- E-Mail: [EMAIL PROTECTED] --- NRA Life Member -- http://www.nra.org --- Debian GNU/Linux Fan -- http://www.debian.org --- CenLA-LUG Founder -- http://www.angelfire.com/la2/cenlalug -- Rincewind had generally been considered by his tutors to be a natural wizard in the same way that fish are natural mountaineers. He probably would have been thrown out of Unseen University anyway-- he couldn't remember spells and smoking made him feel ill. -- Terry Pratchett, The Light Fantastic -- This signature was automatically generated with Signify v1.06. For this and other cool products, check out http://www.debian.org/.
Re: bash manual/info lacks examples
It's been a LONG time since I've use the authentic one-and-only Bourne shell. How many Bourne shell clones do we have floating around here these days? Mike I don't know about clones, but I am typing this on an SGI box where sh _is_ the Bourne shell, and I also have access to a Solaris server where this is true. OTOH I don't think there is a real problem using ksh, ash, zsh, or bash features, unless the first line of your script reads #! /bin/sh HTH, Eric -- E.L. Meijer ([EMAIL PROTECTED]) Eindhoven Univ. of Technology Lab. for Catalysis and Inorg. Chem. (SKA)
Re: bash manual/info lacks examples
On Thu, Aug 05, 1999 at 04:49:38PM +0200, E.L. Meijer (Eric) wrote: It's been a LONG time since I've use the authentic one-and-only Bourne shell. How many Bourne shell clones do we have floating around here these days? Mike I don't know about clones, but I am typing this on an SGI box where sh _is_ the Bourne shell, and I also have access to a Solaris server where this is true. OTOH I don't think there is a real problem using ksh, ash, zsh, or bash features, unless the first line of your script reads #! /bin/sh Yeah, that was what I was referring to originally... I have /bin/sh linked to ash, rather than bash. There was some discussion on the list previously about this (seems a few others are doing the same). I used Bourne shell about 3 years ago when I was a SCO admin, but since then, I've only had access to Linux. Mike [Private mail welcome, but no need to CC: me on list replies.] -- Michael Merten --- E-Mail: [EMAIL PROTECTED] --- NRA Life Member -- http://www.nra.org --- Debian GNU/Linux Fan -- http://www.debian.org --- CenLA-LUG Founder -- http://www.angelfire.com/la2/cenlalug -- /earth is 98% full ... please delete anyone you can. -- This signature was automatically generated with Signify v1.06. For this and other cool products, check out http://www.debian.org/.