分类: LINUX
2010-03-26 20:10:36
其实思路很简单,因为终端中的命令是通过PATH环境变量中的路径搜索的,只要在PATH路径下能找到的可执行文件都可以直接作为命令使用。
var=`echo $PATH|sed "s/:/ /g"` for list in $var; do ls -lR $list|grep -v '^d' done
dbconf2010-03-28 18:45:13
[UPDATE]实现-v开关 cmlist.sh #!/bin/bash paralist=” while getopts “:v” opt; do case $opt in v) paralist=’l’ ;; :) echo “>>> Error: ‘-$OPTARG’ requires an argument” ;; ?) echo “>>> Error: ‘-$OPTARG’ not supported” ;; esac done var=`echo $PATH|sed “s/:/ /g”` for list in $var; do ls -R$paralist $list|grep -v ‘^d’ done 执行: 1、sh cmlist.sh [-v]
dbconf2010-03-28 18:44:54
[UPDATE]添加-v(verbose information)开关,显示命令的相关信息: cmlist.sh #!/bin/bash while getopts ":v" opt; do case $opt in v) var=`echo $PATH|sed "s/:/ /g"` for list in $var; do ls -lR $list|grep -v '^d' done ;; :) echo ">>> Error: '-$OPTARG' requires an argument" ;; ?) echo ">>> Error: '-$OPTARG' not supported" ;; esac done 执行: 1、sh cmlist.sh -v 2、. ./cmlist.sh -v