LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-15-2016, 05:56 PM   #1
ivandi
Member
 
Registered: Jul 2009
Location: Québec, Canada
Distribution: CRUX, Debian
Posts: 528

Rep: Reputation: 866Reputation: 866Reputation: 866Reputation: 866Reputation: 866Reputation: 866Reputation: 866
Slackpkg and "grep -w"


Sometimes slackpkg behaves oddly. For example "slackpkg install aspell" will pull every aspell-* from extra. The same goes for some *python* packages. It turns out that "grep -w" doesn't work for package names like aspell-en.

Quote:
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching
substring must either be at the beginning of the line, or preceded by a non-word constituent character.
Similarly, it must be either at the end of the line or followed by a non-word constituent character.
Word-constituent characters are letters, digits, and the underscore.


Here is a patch for core-functions.sh:

Code:
--- core-functions.sh.orig	2015-12-16 02:01:12.000000000 -0500
+++ core-functions.sh	2016-03-15 18:01:18.000000000 -0400
@@ -591,7 +591,7 @@
 	case "$CMD" in
 		download)
 			for ARGUMENT in $(echo $INPUTLIST); do
-				for i in $(grep -w -- "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
+				for i in $(grep " ${ARGUMENT} " ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
 					LIST="$LIST $(grep " ${i} " ${TMPDIR}/pkglist | cut -f6,8 -d\  --output-delimiter=.)"
 				done
 				LIST="$(echo -e $LIST | sort -u)"
@@ -600,14 +600,14 @@
 		blacklist)
 			for ARGUMENT in $(echo $INPUTLIST); do
 				for i in $(cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
-						grep -w -- "${ARGUMENT}" | cut -f2 -d\  | sort -u); do
+						grep " ${ARGUMENT} " | cut -f2 -d\  | sort -u); do
 					grep -qx "${i}" ${CONF}/blacklist || LIST="$LIST $i"
 				done
 			done
 		;;
 		install|upgrade|reinstall)
 			for ARGUMENT in $(echo $INPUTLIST); do
-				for i in $(grep -w -- "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
+				for i in $(grep " ${ARGUMENT} " ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
 					givepriority $i
 					[ ! "$FULLNAME" ] && continue
 
@@ -634,8 +634,8 @@
 		remove)
 			for ARGUMENT in $(echo $INPUTLIST); do
 				for i in $(cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
-					  	grep -w -- "${ARGUMENT}" | cut -f6 -d\  | sort -u); do
-					PKGDATA=( $(grep -w -- "$i" ${TMPDIR}/tmplist) )
+					  	grep " ${ARGUMENT} " | cut -f6 -d\  | sort -u); do
+					PKGDATA=( $(grep " $i " ${TMPDIR}/tmplist) )
 					[ ! "$PKGDATA" ] && continue
 					LIST="$LIST ${PKGDATA[5]}" 
 					unset PKGDATA
Cheers
Attached Files
File Type: txt slackpkg_grep_word.diff.txt (1.6 KB, 12 views)
 
Old 03-16-2016, 03:59 AM   #2
phenixia2003
Senior Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Hello,

Quote:
Originally Posted by ivandi View Post
Sometimes slackpkg behaves oddly. For example "slackpkg install aspell" will pull every aspell-* from extra. The same goes for some *python* packages. It turns out that "grep -w" doesn't work for package names like aspell-en.
It works:
Code:
$ grep --color -w "aspell-en" /var/lib/slackpkg/pkglist
slackware64 aspell-en 6.0_0 noarch 4 aspell-en-6.0_0-noarch-4 ./slackware64/l txz


$ slackpkg -dialog=off reinstall aspell-en

Looking for aspell-en in package list. Please wait... DONE

aspell-en-6.0_0-noarch-4.txz

Total package(s): 1

Do you wish to reinstall selected packages (Y/n)? n

Quote:
Originally Posted by ivandi View Post
Here is a patch for core-functions.sh
[...]
With this patch, some requests will not be honored anymore.

1. before applying patch:
Code:
$ slackpkg -dialog=off upgrade firefox

Checking local integrity... DONE
Looking for firefox in package list. Please wait... DONE

mozilla-firefox-38.7.0esr-x86_64-1_slack14.1.txz

Total package(s): 1

Do you wish to upgrade selected packages (Y/n)? n

$ slackpkg -dialog=off upgrade mozilla

Checking local integrity... DONE
Looking for mozilla in package list. Please wait... DONE

mozilla-firefox-38.7.0esr-x86_64-1_slack14.1.txz
mozilla-nss-3.23-x86_64-1_slack14.1.txz
mozilla-thunderbird-38.6.0-x86_64-1_slack14.1.txz

Total package(s): 3

Do you wish to upgrade selected packages (Y/n)? n

$ slackpkg -dialog=off upgrade solibs

Checking local integrity... DONE
Looking for solibs in package list. Please wait... DONE

glibc-solibs-2.17-x86_64-11_slack14.1.txz
openssl-solibs-1.0.1s-x86_64-1_slack14.1.txz
seamonkey-solibs-2.40-x86_64-1_slack14.1.txz

Total package(s): 3

Do you wish to upgrade selected packages (Y/n)? n
2. after applying patch:
Code:
$ slackpkg -dialog=off upgrade firefox

Checking local integrity... DONE
Looking for firefox in package list. Please wait... DONE

No packages match the pattern for upgrade. Try:

        /usr/sbin/slackpkg install|reinstall 

$ slackpkg -dialog=off upgrade mozilla

Checking local integrity... DONE
Looking for mozilla in package list. Please wait... DONE

No packages match the pattern for upgrade. Try:

        /usr/sbin/slackpkg install|reinstall 

$ slackpkg -dialog=off upgrade solibs

Checking local integrity... DONE
Looking for solibs in package list. Please wait... DONE

No packages match the pattern for upgrade. Try:

        /usr/sbin/slackpkg install|reinstall
--
SeB
 
Old 03-16-2016, 07:35 AM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,901

Rep: Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025
Quote:
Originally Posted by phenixia2003 View Post
With this patch, some requests will not be honored anymore.
Yes, that was kind of the point.

The best example of the issue is these 3 packages:
at-3.1.12-i486-1
at-spi2-atk-2.18.1-i586-1
at-spi2-core-2.18.3-i586-1

'at' is completely unrelated to the two 'at-spi2-*' packages.
Now try getting slackpkg to do something to 'at' without also impacting the other two.

IMO Ivandi's approach is better and if you want wider matching then you should have to explicitly request it by using wildcards.
 
Old 03-16-2016, 08:16 AM   #4
phenixia2003
Senior Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Hello,

Quote:
Originally Posted by GazL View Post
Yes, that was kind of the point.

The best example of the issue is these 3 packages:
at-3.1.12-i486-1
at-spi2-atk-2.18.1-i586-1
at-spi2-core-2.18.3-i586-1

'at' is completely unrelated to the two 'at-spi2-*' packages.
Now try getting slackpkg to do something to 'at' without also impacting the other two.

IMO Ivandi's approach is better and if you want wider matching then you should have to explicitly request it by using wildcards.
from slackpkg man-page :

Code:
slackpkg [OPTIONS] {install|remove|search|upgrade|reinstall|blacklist} {PATTERN|FILE}

[...]

PATTERN can be a package name or just part of package name.  It can also be  a  software series (like kde, a, ap, ...).
--
SeB
 
Old 03-16-2016, 08:26 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,901

Rep: Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025
Yes, I know. IMO that design is broken.
 
1 members found this post helpful.
Old 03-16-2016, 09:16 AM   #6
ivandi
Member
 
Registered: Jul 2009
Location: Québec, Canada
Distribution: CRUX, Debian
Posts: 528

Original Poster
Rep: Reputation: 866Reputation: 866Reputation: 866Reputation: 866Reputation: 866Reputation: 866Reputation: 866
Quote:
PATTERN can be a package name or just part of package name.
Actually only parts separated by a hyphen from the rest of the package name can be used because "grep -w" matches them as whole words.


Cheers
 
Old 03-16-2016, 10:54 AM   #7
phenixia2003
Senior Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Quote:
Originally Posted by ivandi View Post
Actually only parts separated by a hyphen from the rest of the package name can be used because "grep -w" matches them as whole words.
That makes sense, and I don't see anything wrong here. There are more chance that users issue a slackpkg install firefox or slackpkg install mozilla than a slackpkg install fox, or slackpkg install zilla.


Furthermore, as stated in the man page, a Pattern can also be a software series (ie. kde, a, ap,...). But, with your patch, this does not work anymore :

Code:
slackpkg reinstall slackware64

Looking for slackware64 in package list. Please wait... DONE

No packages match the pattern for reinstall. Try:

        /usr/sbin/slackpkg install|upgrade 


root@blackdog [slackpkg] >slackpkg upgrade patches

Checking local integrity... DONE
Looking for patches in package list. Please wait... DONE

No packages match the pattern for upgrade. Try:

        /usr/sbin/slackpkg install|reinstall

This can be "fixed" by not putting ${ARGUMENT} between spaces :

Code:
--- core-functions.sh.orig.16   2016-03-16 16:26:22.712425439 +0100
+++ core-functions.sh   2016-03-16 16:29:50.726434721 +0100
@@ -591,7 +591,7 @@
        case "$CMD" in
                download)
                        for ARGUMENT in $(echo $INPUTLIST); do
-                               for i in $(grep -w -- "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
+                               for i in $(grep "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
                                        LIST="$LIST $(grep " ${i} " ${TMPDIR}/pkglist | cut -f6,8 -d\  --output-delimiter=.)"
                                done
                                LIST="$(echo -e $LIST | sort -u)"
@@ -600,14 +600,14 @@
                blacklist)
                        for ARGUMENT in $(echo $INPUTLIST); do
                                for i in $(cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
-                                               grep -w -- "${ARGUMENT}" | cut -f2 -d\  | sort -u); do
+                                               grep "${ARGUMENT}" | cut -f2 -d\  | sort -u); do
                                        grep -qx "${i}" ${CONF}/blacklist || LIST="$LIST $i"
                                done
                        done
                ;;
                install|upgrade|reinstall)
                        for ARGUMENT in $(echo $INPUTLIST); do
-                               for i in $(grep -w -- "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
+                               for i in $(grep "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\  | sort -u); do
                                        givepriority $i
                                        [ ! "$FULLNAME" ] && continue
 
@@ -634,8 +634,8 @@
                remove)
                        for ARGUMENT in $(echo $INPUTLIST); do
                                for i in $(cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
-                                               grep -w -- "${ARGUMENT}" | cut -f6 -d\  | sort -u); do
-                                       PKGDATA=( $(grep -w -- "$i" ${TMPDIR}/tmplist) )
+                                               grep "${ARGUMENT}" | cut -f6 -d\  | sort -u); do
+                                       PKGDATA=( $(grep "$i" ${TMPDIR}/tmplist) )
                                        [ ! "$PKGDATA" ] && continue
                                        LIST="$LIST ${PKGDATA[5]}" 
                                        unset PKGDATA
With this code, the pattern passed in argument can be a package name, part of a package name, or even a slackware series :
Code:
$ slackpkg -dialog=off reinstall aspell-en

Looking for aspell-en in package list. Please wait... 
DONE

aspell-en-6.0_0-noarch-4.txz

Total package(s): 1


$ slackpkg -dialog=off reinstall spel

Looking for spel in package list. Please wait... 
DONE

aspell-0.60.6-x86_64-1.txz
aspell-en-6.0_0-noarch-4.txz
gtkspell-2.0.16-x86_64-1.txz
hunspell-1.3.2-x86_64-1.txz
ispell-3.2.06-x86_64-1.txz

Total package(s): 5


$ slackpkg -dialog=off reinstall slackware64

Looking for slackware64 in package list. Please wait...
DONE

ConsoleKit-0.4.5-x86_64-1.txz
...
Total package(s): 1191
However, the returned packages can be unrelated, even more than with current slackpkg :
Code:
slackpkg -dialog=off  reinstall at

Looking for at in package list. Please wait...
DONE
apr-1.5.0-x86_64-1_slack14.1.txz
apr-util-1.5.3-x86_64-1_slack14.1.txz
at-3.1.12-x86_64-1.txz
at-spi2-atk-2.8.1-x86_64-1.txz
at-spi2-core-2.8.0-x86_64-1.txz
...
Total package(s): 76
For instance, apr is selected because it is in patches directory which matches the pattern "at".

--
SeB
 
Old 03-19-2016, 08:00 PM   #8
yars
Member
 
Registered: Apr 2012
Location: Russia
Distribution: Slackware64-current
Posts: 249

Rep: Reputation: 24
As for slackpkg+, I think it will be best solution, to have the re-defineable variable like GREPOPTS=${GREPOPTS:--word-regexp}, for instance, in the configuration file.
 
  


Reply



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
[SOLVED] [ENCHANCEMENT] slackpkg+: do not show the notices "pkglist is older than 24h..." and "remember to re-run 'slackpkg update''..."... yars Slackware 1 01-09-2016 09:56 AM
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
Usage of "-f" option of grep in a script results in "Permission Denied" error zaayu87 Linux - Newbie 3 07-25-2013 12:45 PM
Problem "$value=`mpstat 1 1 | grep "Average"`;" Alias pipe return nothing adamlucansky Linux - General 8 09-25-2009 07:26 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM

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

All times are GMT -5. The time now is 02:39 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