今天看到一个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
如对本文有疑问, 点击进行留言回复!!
如何在Ubuntu 18.04(实体机)上配置OpenWRT的开发环境
网友评论