今天看到一個shell題目,正好拿來練練手
需要在多個目錄中 (如:beijing shanghai tianjin guangzhou 等等) 建立子目錄(以年份命名),然後進入子目錄,建立目錄並以當天的日期命名。
最終的效果是這樣的:
複製代碼 代碼如下:
china/guangdong/
china/guangdong/shenzhen/2010/1206
china/guangdong/shenzhen/2010/1207
china/guangdong/shenzhen/baoan/2010/1206
china/guangdong/shenzhen/baoan/2010/1207
china/guangdong/shenzhen/baoan/guangming/2010/1206
china/guangdong/shenzhen/baoan/guangming/2010/1207
我的實現:
#!/bin/bash read -p "PLEASE input country:" cou read -p "PLEASE input city:" city read -p "PLEASE input name:" name#echo "$cou,$city,$name" date=$(date +%Y)#echo $date date2=$(date +%m%d)# echo $date2 if [ -d "./$cou/$city/$name/$date/$date2" ];then echo "the dir is exit" else mkdir -p ./$cou/$city/$name/$date/$date2 fi
效果:
[root@localhost hbshell]# test.sh
PLEASE input country:china
PLEASE input city:hangzhou
PLEASE input name:hb
#[root@localhost hbshell]# ll china/hangzhou/hb/2011/0321/
總計 0