A shell small case (create date directory) _linux Shell

Source: Internet
Author: User

I saw a shell problem today, just to practice practicing
You need to create subdirectories (named in years) in multiple directories (such as Beijing Shanghai Tianjin Guangzhou, and so on), then enter subdirectories, create new directories, and name them on the day.
The ultimate effect is this:

Copy Code code as follows:

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

My implementation:

#!/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 $date 2
    If [-d]./$cou/$city/$name/$date/$date 2 "];then
        echo" The dir is exit
    else
        mkdir-p./$ cou/$city/$name/$date/$date 2
    fi

Effect:
[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/
Total 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.