Shell Programming Blog Shell Programming Blog

Tuesday, 30 October 2012

Linux Bash Scripting: How to create directories for each day of the current month

Unknown | 09:59 | | 3 Comments so far


Bash Linux Unix shell scripting

 In this post I have written a script that creates an empty directory for each day of the current month. I used cal command to get the date and month instead of using date command. The reason is that the date command does not work in Solaris. To make it portable, I have used cal command.

The below script does the following
  • It takes the total number of days of the current month 
  • It gets the current month name from the cal command
  • It gets the current year from the cal command
  • It creates an empty directory for each day of the current month
  • Before creating, this checks whether the directory already exists, if yes, the script exits by displaying a message.



You can change the "dir" to the directory in which you want the folders to be created.

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming