<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "[Linux]取得每月最後一天的Shell Script"]]></title>
		<link>https://forum.andowson.com/posts/list/16.page</link>
		<description><![CDATA[Latest messages posted in the topic "[Linux]取得每月最後一天的Shell Script"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>[Linux]取得每月最後一天的Shell Script</title>
				<description><![CDATA[ 如果每個月底要計算該月的總使用量，在日期範圍上，我們通常需要找出該月的最後一天。在Linux上用shell script來進行運算時可以參考底下的方法： 
<br>
<br>
[code]#! /bin/bash 
<br>
export LANG=en_US 
<br>
YEAR=`date +%Y` 
<br>
MONTH=`date +%m` 
<br>
<br>
DAYS=`cal $MONTH $YEAR | grep -v "$YEAR" | grep -v "Tu"` 
<br>
for day in $DAYS 
<br>
do 
<br>
 LAST=$day 
<br>
done 
<br>
<br>
echo $LAST 
<br>
[/code] 
<br>
<br>
這個程式的邏輯主要是靠[url=http://www.computerhope.com/unix/ucal.htm]cal[/url]這個指令印出系統月曆的小程式吐出來的結果再用grep -v過濾掉結果的最上面兩行，剩來的就是一個月的每一天了，然後很笨的跑迴圈，跑到最後一圈就是該月的最後一天了。 
<br>
<br>
參考資料： 
<br>
http://www.sun.com/bigadmin/scripts/submittedScripts/last-day.sh.txt]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/145/233.page</guid>
				<link>https://forum.andowson.com/posts/preList/145/233.page</link>
				<pubDate><![CDATA[Wed, 5 Sep 2007 18:51:38]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
	</channel>
</rss>