Unix_Workbench_Solutions

My solutions to the open source book "The Unix Workbench" by Sean Kross"

View on GitHub

5.1 Math

5.1.2 Exercises

  1. Look at the man pages for bc.

     man bc
    

  2. Try doing some math in bc interactively.

     bc -l
    

    When we are done, we type quit or we press ctrl + D


  1. Try writing some equations in a file and then provide that file as an argument to bc.

    We write some equations in a file

     echo "22 / 7" > equ.txt
     echo "3 + 4" >> equ.txt
     echo "5.2 * 6" >> equ.txt
    

    We can now use one of two methods

    ### Method 1: Directly running bc with the file as an argument

     bc -l equ.txt # Will enter the interactive mode
    

    or

     bc -l < equ.txt # Won't enter the interactive mode
    

    ### Method 2: Pipe the file contents as arguments to the bc command

     cat equ.txt | bc -l # Won't enter the interactive mode