日期:2014-05-16  浏览次数:20618 次

老师布置的作业。。。。看不懂呀,,求指点………………
1. num=10 ## number of files to print
2. short=0 ## set to 1 for short listing
3. timestyle='--time-style="+ %d-%b-%Y %H:%M:%S "' ## GNU-#specific time format
4. opts=Aadn:os 
5. while getopts $opts opt
6. do
7. case $opt in
8. a|A|d) ls_opts="$ls_opts -$opt" ;; ## options passed to ls 
9. n) num=$OPTARG ;; ## number of files to display
10. o) ls_opts="$ls_opts -r" ;; ## show oldest files, not newest
11. s) short=$(( $short + 1 )) ;;
12. esac 
13. done
14. shift $(( $OPTIND - 1 )) 
15. case $short in
16. 0) ls_opts="$ls_opts -l -t" ;; ## long listing, use -l
17. *) ls_opts="$ls_opts -t" ;; ## short listing, do not use -l
18. esac 
19. ls $ls_opts $timestyle "$@" | {
20. read ## In bash, the same as: IFS= read -r REPLY
21. case $line in
22. total*) ;; # ???
23. *) printf "%s\n" "$REPLY" ;;
24. esac 
25. cat
26. } | head –n $num



------解决方案--------------------
获取命令行参数,然后干点什么.
------解决方案--------------------
执行下试试
------解决方案--------------------
这个就是实现一个个性化的 ls

根据命令行选项,显示不同的输出格式