1 说明
因为shell比较简单,需要的语句可以随时上网查,这篇工具书不准备进行详尽的编写,只是记录简单的几个例子,以便将来有需要的时候拿来用。
1.1 运行
执行当前目录下的myShell.sh文件
sh ./myShell.sh
2. 案例集合
2.1 创建目录及循环创建文件
#!/bin/sh
mkdir shell_test
cd shell_test
for ((i=0; i<10; i++)); do
touch test_$i.txt
done
2.2 循环进入目录并创建文件
#!/bin/sh
for dir in `ls`; do
if [ -d $dir ]; then
echo $dir "is a folder"
cd $dir;
touch test_$i.txt
cd ..;
else
echo $dir "is a not folder"
fi
done
2.3 批量拉git项目
#!/bin/sh
for dir in `ls`; do
if [ -d $dir ]; then
echo $dir "is a folder, enter to pull git"
cd $dir;
git pull;
cd ..;
else
echo $dir "is a not folder, skip"
fi
done