Arithmetic Operations

  • + 0 comments

    read -r exp

    awk "BEGIN { printf \"%.3f\n\", $exp }"

    • BEGIN keyword tells AWK to execute the code without any inputs files or stdin
    • Does a shell expansion of $exp and evaluates the expression to 3 d.p.
    • On a side note the backslash after printf is to escape the double quotes so that awk can treat that as a literal double quote.