开发者

Cshell Script date issue

Is there a way to add date in the name of the file... we can 开发者_Go百科add current date in this manner date '+%Y%m%d' but i want to add "filename_date_1-2-2011_thru_31-2-2011.txt" Is it possible to do that??????????


If you have a sufficiently advanced version of the date command and you know a Unix timestamp for the start and end dates, then you can use:

  • (MacOS X) date -r 1234567890 "+%d-%m-%Y" to obtain 13-02-2009.
  • (GNU) date -d 2/13/2009 "+%d-%m-%Y" to obtain 13-02-2009 again.

If you don't want the leading zeroes on the day of month, then you need to use '%e` instead of '%d' on Linux (but that puts a space in place of the zero). It is not clear that there's a format specifier for day-of-month without a leading zero on MacOS X; nor is it clear that there's a way to format month of year as a single-digit number for January to September on either platform.

You get the format into your C shell script using back-ticks around the date commands.

Consider reading Csh Programming Considered Harmful and heeding its advice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜