1、从文件读取 while read line do echo "line=$line" done < file.txt 2、将字符串转换为数组,并进行遍历 str="html, css, javascript, java, php, go, python" arr=(${str//,/ }) for item in ${arr[@]} do echo "item=$item" done 3、将目录转换为字符串 ls | xargs -d' ' echo |awk 'BEGIN{i=0;} { if(i > 0){ printf(",");} i++;printf("%s", $0);}' 4、递归 function find(){ local dir=$1 local arr=( $(ls $dir) ) for item in ${arr[@]} do local path="$dir/$item" if [ -L $path ] then echo "ln $path" find $path elif [ -d $path ] then echo "dir $path" find $path else echo "file path=$path, dir=${path%/*}, filename=${path##*/}" fi done } 备注: 获取当前路径下的目录:${path%/*} 获取当前路径下的文件名:${path##*/}