Shell脚本

输出目录/home/yangkai/shell/20/下的所有文件:

1 files=`find /home/yangkai/shell/20/ -name "*.txt"`
2 
3 echo $files

将得到的文件存放到一个数组中:

1 #! /bin/bash
2 
3 files=`find /home/yangkai/shell/20/ -name "*.txt"`
4 
5 arr=(${files//,/})
6 
7 echo ${arr[0]}

判断一个字符串是不是包含另一个字符串:

#!/bin/bash

tmp="Hello World"
tstring="World"
if [[ ${tmp} == *$tstring* ]]
then
    echo "YES"
else 
    echo "NO"
fi

注释:

1 #! /bin/bash
2 
3 #files=`find /home/yangkai/shell/20/ -name "*.txt"`
4 
5 :<<BLOCK
6 echo "ok"
7 BLOCK
8 
9 echo "finish"

数组:

1 #! /bin/bash
2 
3 a=(1 2 3 4 5)
4 
5 echo $a
6 echo ${a}
7 echo ${a[@]}
8 
9 echo ${#a[@]}

 

posted @ 2016-10-02 13:53  BelFuture  阅读(247)  评论(0编辑  收藏  举报
The horizon of life is broadened chiefly by the enlargement of the heart.