闲来无事,写几个shell script来练练手,发现我的mac下的shell和ubuntu下的shell有些语法还是有区别,网上的一些教程,在我的mac上并不适用,需要修改。
1、编写shell脚本,将/users/sunwangdong/desktop/wordcount下的大于10000k的文件信息输出
我写了一个名字为test.sh的脚本,如下所示:
#!/bin/bash
for FILE in `ls /users/sunwangdong/desktop/wordcount/`
do
#echo $FILE
if [ -f "/users/sunwangdong/desktop/wordcount/$FILE" ]
then
#echo $FILE
if [ `ls -al /users/sunwangdong/desktop/wordcount/$FILE | awk '{print $5}'` -lt 10000 ]
then
ls -al /users/sunwangdong/desktop/wordcount/$FILE | awk '{print $0}'
fi
fi
done
其中,第一行的for循环中,内部需要用反斜号`来表示ÿ