Hi mocore
Sorry for the delay and this long winded reply.
I originally did something similar to mk_exp() to load the search
terms into a variable. Only I wanted to use built in commands so I
was using a case statement. Problem was the case statement won't
interpret the or symbol when it's embedded in a variable.
That lead me to a simpler solution, parse /usr/local/tce.installed
directly. The ls command is not needed for this, so it can still
be done using only built in commands.
Like yours, I can also search for extensions beginning with z and s:
tc@E310:~/tce-status$ ./tce-status -f z* s*
zip-unzip
zlib_base-dev
zstd
zsync
schumacher-clean-fonts
sed
shared-mime-info
slang
socat
sox
speex
sqlite3
sqlite3-bin
squashfs-tools
strace
submitqc
syslinuxbut I don't need anchors to do it.
or starting with o and ending with l:
tc@E310:~/tce-status$ ./tce-status -f o*l
opensslThat doesn't work with your version:
tc@E310:~/tce-status$ ./tce-status2 -i o*l | wc -l
202That's because grep needs the asterisk escaped with a period:
tc@E310:~/tce-status$ ./tce-status2 -i o.*l
Xorg-7.7-lib
alsa-modules-4.19.10-tinycore
cdrtools
compiletc
coreutils
dosfstools
getlocale
glibc_i18n_locale
hicolor-icon-theme
inotify-tools
libopenal
mtools
net-tools
openldap
openssl
openssl-1.1.1
poppler07
poppler07-bin
postgresql-12-client
rollcall
squashfs-tools
twolame
xdotool
xf86-video-intelStill not what I was looking for, you need anchors at both ends of the search term:
tc@E310:~/tce-status$ ./tce-status2 -i ^o.*l$
opensslEven adding -w (Match whole words only) to your grep command didn't quite fix it:
tc@E310:~/tce-status$ ./tce-status2 -i o.*l
openssl
openssl-1.1.1That second entry ends with a 1, not an l.
Piping the while getopts loop through your f2 function and testing for extra parameters
was clever, but I see other issues.
The 3 options output different data formats.
-i ExtensionName
-u ExtensionName.tcz
-o ExtensionName.tcz and/or ExtensionName.tcz.md5.txt and/or ExtensionName.tcz.dep
It checks every *.tcz* file it finds.
I chose -i because:
1. I use it fairly often.
2. It shows up in the forum sometimes.
3. It was simple to implement, all of the info is in /usr/local/tce.installed.
I avoided -u because:
1. I don't think I've ever used it.
2. I didn't have a plan for dealing with the 2 different data formats.
3. I was not aware of your clever piping trick.
I avoided -o because:
1. It can take a very long time to run (about 8 minutes on one of my machines).
2. If you use the wrong search filter, it can take a very long time to run again.
In light of your piping trick, I may take another look at -u.
I also feel the globbing patterns are easier for the average person to understand
than the regex patterns.
... and i dont recall seeing
>Params=${@/-f/}
trick before !
It can be quite useful:
Find/replace pattern in variable
${var/Pattern/Replacement} First match of Pattern, within var replaced with Replacement.
${var//Pattern/Replacement} All matches of Pattern, within var replaced with Replacement.
${var/#Pattern/Replacement} Prefix of var matches Pattern, Pattern replaces Replacement.
${var/%Pattern/Replacement} Suffix of var matches Pattern, Pattern replaces Replacement.
# If Replacement is omitted, then Pattern is replaced by nothing, that is, deleted.