tailieunhanh - Unix Shell Programming Third Edition phần 5
Sau đó, bạn có thể chỉ cần viết tên và số, ngăn cách với nhau bởi một ký tự tab, vào cuối của file danh bạ:Mặc dù bạn không có thể nói, có một ký tự tab phân cách $ 1 từ $ 2 lệnh echo trước. Tab này phải được trích dẫn để làm cho nó vang vọng mà không nhận được ăn ngấu nghiến lên vỏ. Hãy thử chương trình: | do run file done request id is laseri-33 standard input request id is laseri-34 standard input request id is laseri-35 standard input request id is laseri-36 standard input The four words memoi memo2 memo3 and memo4 will be assigned to the variable file in order and the run program will be executed with the value of this variable as the argument. Execution will be just as if you typed in the four commands run memol request id is laseri-33 standard input run memo2 request id is laseri-34 standard input run memo3 request id is laseri-35 standard input run memo4 request id is laseri-36 standard input Incidentally the shell permits filename substitution in the list of words in the for meaning that the previous loop could have also been written this way for file in memo 1-4 do run file done And if you wanted to run all the files in your current directory through run you could type for file in do run file done If the file filelist contains a list of the files that you want to run through run you can type files cat filelist for file in files do run file done to run each of the files or more succinctly for file in cat filelist do run file done If you found that you were using the run program often to process several files at once you could go inside the run program and modify it to allow any number of files to be passed as arguments to the program. cat run process files through nroff version 2 for file in do tbl file nroff -rom -Tlp Ip done Recall that the special shell variable stands for all the arguments typed on the command line. So if you executed the new version of run by typing run memol memo2 memo3 memo4 the in the for s list would be replaced by the four arguments memo1 memo2 memo3 and memo4. Of course you could also type run memo 1-4 to achieve the same results. The @ Variable While we re on the subject of let s look at it in a bit more detail. We ll write a program called args that displays all the arguments typed on the command line one per .
đang nạp các trang xem trước