1.字典操作
1.1定义字段
declare -A mapfile
mapfile=(
[file1]=/home/abc/test1.txt'
[file2]='/home/abc/test2.txt'
[file3]='/home/abc/test2.txt'
[file4]='/home/abc/test3.txt'
[file5]='/home/abc/test4.txt'
)
1.2遍历字典
for node_file in ${mapfile[@]}
do
echo ${node_file}
done
2.字符串操作
opt_path=$1
pattern=".cpp"
2.1为空判断
if [ -z "$opt_path" ]; then
echo "run param is empty"
exit
fi
2.2包含处理
if [[ $opt_path =~ $pattern ]]; then
echo "ok"
fi
2.3字符串以.h或者.cpp结尾
if [[ $opt_path = *.h ]] || [[ $opt_path = *.cpp ]]; then
echo "this file ok"
fi
3.递归遍历文件夹
function read_dir()
{
for file in `ls $1`
do
cur=$1/$file
if [ -d $cur ]; then
#echo $cur
read_dir $cur
else
echo $cur
fi
done
}
4.数字相等判断
findflag=1
if [ $findflag -eq 1 ]; then
echo "findflag == 1"
fi
5.当前目录下文件类型判断
for i in `ls`;
{
if [ -f $i ]; then
echo $i--file;
else
echo $i--directory
fi
}