tailieunhanh - Mastering unix shell scripting p9

Truy vấn hệ thống tên kịch bản này # Kiểm tra số lượng chính xác của đối số - chính xác 1 if (($ # = 1)) sau đó echo "\ nERROR: Cách sử dụng lỗi . thoát khỏi ." sử dụng fi # tên tập tin làm chúng tôi cần để làm cho độc đáo? BASE_FN = $ 1 RANDOM = $ $ # Lấy tên tập tin cơ sở để làm cho độc đáo # Khởi tạo các biến môi trường RANDOM # với quá trình ID (PID) | 538 Chapter 21 Put anything you want to process in this function. I recommend that you specify an external program of shell script to execute. echo HELLO WORLD - DATE_ST UNIQUE_FN No-Op - Does nothing but has a return code of zero BEGINNING OF MAIN SCRIPT_NAME basename 0 Query the system for this script name Check for the correct number of arguments - exactly 1 if 1 then echo nERROR Usage . usage fi What filename do we need to make unique BASE_FN 1 Get the BASE filename to make unique RANDOM Initialize the RANDOM environment variable with the current process ID PID UPPER_LIMIT 32767 Set the UPPER_LIMIT CURRENT_SECOND 99 Initialize to a nonsecond LAST_SECOND 98 Initialize to a nonsecond USED_NUMBERS Initialize to null PROCESSING TRUE Initialize to run mode while PROCESSING TRUE do DATE_ST get_date_time_stamp Get the current date time CURRENT_SECOND get_second Get the current second RN in_range_fixed_length_random_number_typeset Get a new number Check to see if we have already used this number this second if CURRENT_SECOND LAST_SECOND Listing shell script listing. continued Pseudo-Random Number Generation 539 then UNIQUE FALSE Initialize to FALSE while UNIQUE TRUE -z UNIQUE do Has this number already been used this second echo USED_NUMBERS grep RN dev null 2 1 if 0 then Has been another number RN in_range_fixed_length_random_number else Number is unique this second. UNIQUE TRUE Add this number to the used number list USED_NUMBERS USED_NUMBERS RN fi done else USED_NUMBERS New to null fi Assign the unique filename to the UNIQUE_FN variable UNIQUE_FN BASE_FN . DATE_ST . RN echo UNIQUE_FN Comment out this line LAST_SECOND CURRENT_SECOND Save the last second value We have a unique filename. PROCESS SOMETHING HERE AND REDIRECT OUTPUT TO UNIQUE_FN my_program IF PROCESSING IS FINISHED ASSIGN FALSE to the PROCESSING VARIABLE if MY_PROCESS done then PROCESSING FALSE fi done Listing .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.