- 论坛徽章:
- 0
|
关于文件名自动生成
[quote]原帖由 \"大脚王\"]我需要每天生成一个含有昨天日期的文件名,例如:今天是3月24好,那么我生成的文件名就是:MO20030323.TXT。请问如何在SHELL中实现??因为我是新手,请大家帮帮忙,谢谢!!![/quote 发表:
Hi,
Here is a short script that you can use:
-----------------------------
#!/usr/bin/sh
perl -le \'print scalar localtime time - 86400\' | read junk MON DAY junk YR
case $MON in
Jan) MON=01;;
Feb) MON=02;;
Mar) MON=03;;
Apr) MON=04;;
May) MON=05;;
Jun) MON=06;;
Jul) MON=07;;
Aug) MON=08;;
Sep) MON=09;;
Oct) MON=10;;
Nov) MON=11;;
Dec) MON=12;;
esac
echo \"File name is: MO$YR$MON$DAY.TXT\"
-------------------------------------------------------
This will take care of the leap year, and 28 days in Feb, etc.
Hope this helps. |
|