当前位置: 技术问答>linux和unix
老师布置的作业。。。。看不懂呀,,求指点………………
来源: 互联网 发布时间:2017-02-27
本文导语: 1. num=10 ## number of files to print 2. short=0 ## set to 1 for short listing 3. time+ %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. ...
1. num=10 ## number of files to print
2. short=0 ## set to 1 for short listing
3. time+ %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 "%sn" "$REPLY" ;;
24. esac
25. cat
26. } | head –n $num
2. short=0 ## set to 1 for short listing
3. time+ %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 "%sn" "$REPLY" ;;
24. esac
25. cat
26. } | head –n $num
|
这个就是实现一个个性化的 ls
根据命令行选项,显示不同的输出格式
根据命令行选项,显示不同的输出格式
|
获取命令行参数,然后干点什么.
|
执行下试试