LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-22-2013, 08:59 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157
Bash and wildcard problem with alphanumeric package versions


Hi,

I have a helper script trim_server_base.sh that does two things:
  1. Install needed packages
  2. Remove unneeded packages

The script reads package names from two different text files and then proceeds to remove unwanted packages and to add needed packages. Here's a part of it:

Code:
CWD=$(pwd)

CRUFT=$(egrep -v '(^\#)|(^\s+$)' $CWD/pkglists/server-base-remove)
INSTALL=$(egrep -v '(^\#)|(^\s+$)' $CWD/pkglists/server-base-add)

for PACKAGE in $CRUFT; do
  if [ -r /var/log/packages/${PACKAGE}-[0-9]* ] ; then
    /sbin/removepkg ${PACKAGE} 
  fi
done

unset PACKAGES

for PACKAGE in $INSTALL; do
  if [ ! -r /var/log/packages/${PACKAGE}-[0-9]* ] ; then
    PACKAGES="$PACKAGES $PACKAGE"
  fi
done

if [ -z $PACKAGES ]; then
  continue
else
  /usr/sbin/slackpkg install $PACKAGES
fi
Once slackpkg is configured correctly, the script works as expected... except for those Slackware packages with weird alphanumeric package version strings. Here's some examples from Slackware 14.0
  • cdparanoia-III_10.2-i486-1
  • libjpeg-v8a-i486-1
  • iputils-s20101006-i482-2
  • netdate-bsd4-i486-1

How can I "expand" my Bash syntax to fit these special cases?

Cheers,

Niki

Last edited by kikinovak; 12-22-2013 at 09:25 AM.
 
Old 12-22-2013, 10:23 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
Do these server-base files have package names only, without the version-arch-build string? I have found -f/-x* sort of tests to give strange results. You're probably gonna have to parse full package names to get the NAME part separate because "/var/log/packages/${PACKAGE}-*" alone would give inaccurate results. Post a bit of the input files so we can see the syntax.
 
Old 12-22-2013, 11:49 AM   #3
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157Reputation: 2157
OK, after much experimenting and an IRC conversation with AlienBob and much more experimenting, here's a working solution:

https://github.com/kikinovak/slackwa...server_base.sh

Probably an unusual approach, but hey, it works.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash string comparisons wildcard casperdaghost Programming 5 08-10-2012 04:30 AM
[SOLVED] BASH Wildcard * and ? cwilliams6419 Linux - Newbie 4 02-24-2012 01:19 PM
bash wildcard expansion length issue scazz Linux - Newbie 2 11-01-2011 01:32 PM
Wildcard/regex in bash command logicalfuzz Linux - General 2 10-27-2011 03:40 PM
bash in ubuntu: save the wildcard expansion beebop Programming 0 03-12-2006 02:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration