tailieunhanh - Unix Shell Programming Third Edition phần 7

Viết một chương trình gọi là mymv nào với lệnh mv những gì mycp không với lệnh cp. Làm thế nào nhiều thay đổi, bạn phải làm cho mycp để sản xuất chương trình mới này? Sửa đổi mycp để nhắc nhở cho các đối số nếu không được cung cấp. Một thực hiện điển hình của phiên bản sửa đổi như sau: | Team LiB -I PREVIOUS NEXT The set Command The shell s set command is a dual-purpose command it s used both to set various shell options as well as to reassign the positional parameters 1 2 and so forth. The -x Option This option turns on trace mode in the shell. It does to the current shell what the command sh -x ctype a did for the execution of the ctype program in Chapter 8 Decisions Decisions. From the point that the set -x command is executed all subsequently executed commands will be printed to standard error by the shell after filename variable and command substitution and I O redirection have been performed. The traced commands are preceded by plus signs. x set -x Set command trace option echo x echo add greetings lu rem rolo add greetings lu rem rolo cmd wc cmd wc Is cmd -l ls wc -l 5 You can turn off trace mode at any time simply by executing set with the x option set x set x Is wc -l 5 Back to normal You should note that the trace option is not passed down to subshells. But you can trace a subshell s execution either by running the shell with the -x option followed by the name of the program to be executed as in sh -x rolo or you can insert a set -x command inside the file itself. In fact you can insert any number of set -x and set x commands inside your program to turn trace mode on and off as desired. set with No Arguments If you don t give any arguments to set you ll get an alphabetized list of all the variables that exist in your environment be they local or exported set Show me all variables CDPATH users steve usr spool EDITOR bin vi HOME users steve IFS LOGNAME steve MAIL usr spool mail steve MAILCHECK 600 PATH bin usr bin users steve bin . PHONEBOOK users steve phonebook PS1 PS2 PWD users steve misc SHELL usr bin sh TERM xterm TMOUT 0 TZ EST5EDT cmd wc x Using set to Reassign Positional Parameters There is no way to directly assign a value to a positional parameter for example 1 100 does not work. These parameters are initially set on execution of