首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

老师布置的作业。看不懂呀,求指点…解决办法

2012-06-14 
老师布置的作业。。。。看不懂呀,,求指点………………1.num10## number of files to print2.short0## set to 1 for

老师布置的作业。。。。看不懂呀,,求指点………………
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

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

热点排行