[NTLUG:Discuss] Script question: give me the next sequential filename....
Fred James
fredjame at concentric.net
Mon Mar 31 11:13:37 CST 2003
Jack Snodgrass wrote:
>On Mon, 31 Mar 2003 10:23:19 -0600, Michael Farnham wrote:
>
>
>
>>On Monday 31 March 2003 09:41, Jack Snodgrass wrote:
>>
>>
>>>I need to create a log. It needs to be called
>>>makefile.yymmdd-x where
>>>makefile.yymmdd can be done with something like
>>>makefile.`date +DATE: '%y%m%d`
>>>
>>>...now the catch... the first time I run this today, I want
>>>makefile.030331-1
>>>the next time I want
>>>makefile.030331-2
>>>and then
>>>makefile.030331-3
>>>etc.
>>>
>>>
>>>
>>Something like this should work
>>
>>#!/bin/bash
>>
>>declare -i n
>>pattern=makefile.`date +'%y%m%d'`-
>>n=`ls -1 $pattern | wc -l`
>>n=n+1
>>pattern=$pattern$n
>>echo $pattern
>>exit 0
>>
>>HTH
>>Mike Farnham
>>
>>
>
>thanks... I needed to use
>n=`ls -1 $pattern* 2>/dev/null | wc -l`
>instead of your line as-is but other than that, it works great.
>The * was needed or it didn't work well at all. The 2> /dev/null
>hides the "file not found" error the first time it's run.
>
>Thanks again - jack
>
>
>
>_______________________________________________
>https://ntlug.org/mailman/listinfo/discuss
>
>
>
>
Does "declare -i n" initialize "n" to 0, NULL, or junk?
--
"It's not nice to fool Mother OS." --anonymous
More information about the Discuss
mailing list