Trong giải pháp này kịch bản, chúng tôi cho người sử dụng khả năng nhận xét các nút cụ thể trong các $ PINGFILE. Chúng tôi giao các danh sách của các nút, mà là một danh sách mà không có ý kiến, để một biến. Điều này là tốt cho một danh sách tương đối ngắn của các nút, | Floating-Point Math and the bc Utility Have you ever had a need to do some floating-point math in a shell script If the answer is yes then you re in luck. On Unix machines there is a utility called bc that is an interpreter for arbitrary-precision arithmetic language. The bc command is an interactive program that provides arbitrary-precision arithmetic. You can start an interactive bc session by typing bc on the command line. Once in the session you can enter most complex arithmetic expressions as you would in a calculator. The bc utility can handle more than I can cover in this chapter so we are going to keep the scope limited to simple floating-point math in shell scripts. In this chapter we are going to create shell scripts that add subtract multiply divide and average a list of numbers. With each of these shell scripts the user has the option of specifying a scale which is the number of significant digits to the right of the decimal point. If no scale is specified then an integer value is given in the result. Because the bc utility is an interactive program we are going to use a here document to supply input to the interactive bc program. We will cover using a here document in detail throughout this chapter. Syntax By now you know the routine We need to know the syntax before we can create a shell script. Depending on what we are doing we need to create a mathematical statement to 545 546 Chapter 22 present to bc for a here document to work. A here document works kind of like a label in other programming languages. The syntax that we are going to use in this chapter will have the following form VARIABLE bc LABEL scale SCALE MATH_STATEMENT LABEL The way a here document works is some label name in this case LABEL is added just after the bc command. This LABEL has double redirection for input into the interactive program bc LABEL. From this starting label until the same label is encountered again everything in between is used as input to the bc program. By doing .