On Friday 22 August 2008 23:07, David C. Rankin wrote:
Listmates,
Every time a new fglrx driver comes out, I end up dorking with my script for automating the install from the ATi binary to try and improve it. Tonight is no different.
The task: "I may have several versions of the fglrx rpm in the directory where the script is running or in /usr/src/packages/RPMS/.. and I want the script to automatically select the latest one to install. Such as (names for testing purposes only):
-rw-r--r-- 1 david dcr 21355823 2008-08-22 21:08 fglrx64_7_1_0_SUSE110-8.522-1.x86_64.rpm -rw-r--r-- 1 david dcr 0 2008-08-22 23:47 fglrx64_7_1_0_SUSE110-8.523-1.x86_65.rpm -rw-r--r-- 1 david dcr 0 2008-08-22 23:47 fglrx64_7_1_0_SUSE110-8.524-1.x86_66.rpm
Specifically what I need help solving is "what is the best way to select the newest fglrx rpm from the present directory to install?" I can do it 3 different ways, but all rely on file creation time (ls -t) and seem horribly inefficient. Using the version number would seem to be a better way. So far I have:
In addition to the usual and default glob pattern matching, there is full regular expression matching in BASH. Look in the manual page for a double left bracket, '[['. If you search in "less" (used automatically usually when you run "man"), you'll need to escape them both when used as search patters: "\[\[". Next, you should (in general) be aware of the variable expansion syntax that can apply substitutions to the value while expanding the variable: ${varName#leftStripMinimalPattern} ${varName##leftStripMaximalPattern} ${varName%rightStripMinimalPattern} ${varName%rightStripMaximalPattern} ${varName/replacePattern/firstMatchReplacement} ${varName/replacePattern//allMatchesReplacement} Again, check the manual page for the details. This is enough to detect and dissect the names you want. The "rpm" command can present arbitrary and detailed information about an RPM driven by a format argument of your specification. This is the definitive information about the RPM, of course, so it would be the best thing on which to base a selection. Lastly, when you're dealing with real date strings, they can be decoded by the "date" command and rendered into a linear "seconds since the epoch" date encoding, which allows easy comparison.
...
What says the brain trust?
I don't trust my brain, why would you?
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org