Timothy Bolz wrote:

> Is there a bash commnad similiar to scanf in C or would you have to
> use C for this?

There is read.  Read separates an input line into words, but the
shell generally doesn't distinguish between numbers and strings.

        $ read a b
        3 4
        $ echo $a
        3
        $ echo $b
        4

> Is there a way to print line #x ?  

Yes.  I'd use sed.

        $ sed -n 12p /etc/passwd
        operator:x:11:0:operator:/root:

> Is there a comand which does decimal math?

Yes.  The command is "expr".

        $ expr 3 + 4
        7
        $ expr 3 \* 4                   # note: must quote '*'
        12
        $ expr 3 + 4 \* 5
        23
        $ expr \( 3 + 4 \) \* 5         # also quote '()'
        35

You can combine that with shell variables and command interpolation
(i.e., commands in backticks) like this.

        $ x=3
        $ y=4
        $ z="`expr $x + $y`"
        $ echo $z
        7

Also, you can use bc and dc for more complex stuff.

        $echo 3 + 4 | bc
        7
        $ echo 3 4 + p | dc
        7

So you're writing a program that reads numeric input, does arithmetic
calculations, and prints selected lines from a file.  You can do all
that in bash, but it might be time to look at a real scripting
language such as Python or Perl.

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     [EMAIL PROTECTED]

Reply via email to