今天看到一個shell題目,正好拿來練練手
需要在多個目錄中 (如:beijing shanghai tianjin guangzhou 等等) 創建子目錄(以年份命名),然后進入子目錄,新建目錄并以當天的日期命名。
最終的效果是這樣的:
我的實現:
#!/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
新聞熱點
疑難解答