Tiny Core Base > TCB Tips & Tricks
How to find which extension provides a file
CNK:
--- Quote from: Rich on November 20, 2024, 12:36:55 AM ---
--- Quote from: CNK on November 19, 2024, 11:33:55 PM --- ... The 1s ping might be so short it gives false negatives sometimes ...
--- End quote ---
If I change it to this:
--- Code: ---ping -A -W 1 -c 2 8.8.8.8 2>&1 > /dev/null
--- End code ---
It timed out in 2 seconds with no connectivity and still
returned instantly with connectivity.
The -A flag made the instant response possible:
--- Code: ----A Ping as soon as reply is recevied
--- End code ---
--- End quote ---
-A isn't supported by GNU Inetutils Ping. With inetutils.tcz loaded I get:
--- Code: ---ping: invalid option -- 'A'
--- End code ---
Ping (surprisingly) isn't covered by useBusybox(), so the script needs to use /bin/ping if using -A.
Rich:
Hi CNK
Thanks for the heads up. ping changed to /bin/ping.
Rich:
Hi GNUser
--- Quote from: Rich on November 20, 2024, 02:54:48 PM --- ... Latest version attached. Give it a shake and let me know if any bugs fall out. ;D ...
--- End quote ---
I did some more testing and found it ignored + signs and choked on the [ character.
I did some work on sanitizing the input and it seems to handle almost everything:
--- Code: ---tc@E310:~/Scripting/Provides$ ./provides.sh be@latin.strings
abiword.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh corrupt_t1#P#p1.MYI
mariadb-10.3-test.tcz
mariadb-10.4-test.tcz
mariadb-test.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh 100%_Opaque.myb
mypaint-brushes.tcz
mypaint.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh 9vx-iso
9vx.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh [
coreutils.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh {972ce4c6-7e08-4474-a285-3208198ce6fd}
firefox-ESR.tcz
icecat.tcz
kompozer.tcz
minefield21.tcz
palemoon.tcz
seamonkey-noSSE2.tcz
seamonkey.tcz
thunderbird.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh NetSNMP::ASN.3
net-snmp-dev.tcz
net-snmp-doc.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh ISO_8859-1,GL.gz
glibc_i18n_locale.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh avahi-ui-gtk3~1.desktop
avahi-ui-gtk3.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh c++filt
binutils.tcz
tc@E310:~/Scripting/Provides$ ./provides.sh AAC_\(Nero_FAAC\).txt
deadbeef.tcz
tc@E310:~/Scripting/Provides$
--- End code ---
As you can see, it handles @ # % _ - [ { } : , ~ and +.
It also handles ! and should work with ^ , the provides.db had no ^ characters.
I couldn't get it to accept ( or ), so those need to be escaped. i.e. \( and \).
The $ sign can only be used at the end as an anchor, no where else.
The following should be avoided because the shell grabs them & | " ' ` < >.
You can try escaping them, but I'd hope none of the file names use them.
Edit: It also handles ! ^ = and ].
--- Quote --- ... I'll start looking into adding an environmental variable for advanced users.
--- End quote ---
Accommodations for a PROVIDESUPDATE environmental variable have been added.
It's documented right in the beginning of the script if you want to use it.
polikuo:
Hi, Rich
How about escaping everything that's not alphanumeric into hex for pattern matching ?
awk script
--- Code: ---tc@pi4:/mnt/mmcblk0p2/notes/Shell-Tricks$ cat hex.awk
#!/usr/bin/awk -f
function hex(h,_,r,cmd) {
cmd = "printf \x27" h "\x27 | hexdump -e \x272/1 \x22%X\x22\x27"
cmd | getline r
close(cmd)
return r
}
function qry2ptn(str,_,i,c,s) {
for (i=1;i<=length(str);i++){
c = substr(str,i,1)
if(c ~ /[[:alnum:]]/) s = s c
else {
if(c ~ /\x27/) s = s "\x5Cx27" # single quote
else if(c ~ /\x25/) s = s "\x5Cx25" # %
else s = s "\x5Cx" hex(c)
}
}
return s
}
{
print qry2ptn($0)
}
--- End code ---
Example run
--- Code: ---$ printf '\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x3A\x3B\x3C\x3D\x3E\x3F\x40\x5B\x5C\x5D\x5E\x5F\x60\n' > ptn
$ cat ptn
!"#$%&'()*+,-./:;<=>?@[\]^_`
$ ./hex.awk ptn
\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x3A\x3B\x3C\x3D\x3E\x3F\x40\x5B\x5C\x5D\x5E\x5F\x60
--- End code ---
The only thing that needs adjusting is the leading "^" and the trailing "$" that are defined by your script for special purpose.
Rich:
Hi polikuo
Thanks, but most non-alphanumeric don't even need to be escaped.
As I said in reply #36:
--- Quote ---That was the plan:
Use a / to mark the beginning of the search term if desired.
Type in your search term.
Use a $ sign to mark the end of the search term if desired.
Hit enter.
--- End quote ---
I am:
1. Trying to simplify the search so you don't need to enter or learn
escape or quoting techniques to find what you're looking for.
2. Make the search return a tiny list instead of hundreds of results.
This version of provides.sh can accept the following characters in the command line:
--- Code: ---! # % + , - . / : = ? @ [ ] ^ _ { } ~ and blank spaces
--- End code ---
Most appear in various provides.db files.
All have been tested.
I have not found the following in any provides.db files:
--- Code: ---< > & * ; ' " `
--- End code ---
The shell will try to act on them and may do bad things.
The shell will try to act on these but I found them in TC10 x86 provides.db file:
--- Code: ---( )
--- End code ---
It is a short list and you don't need ( or ) to find any of them:
--- Code: ---tc@E310:~/Scripting/Provides$ grep '(' /etc/sysconfig/tcedir/provides.db
usr/local/share/gtk-doc/html/cairo/cairo-Quartz-(CGFont)-Fonts.html
/usr/local/lib/deadbeef/convpresets/AAC_(Nero_FAAC).txt
/usr/local/lib/deadbeef/convpresets/FLAC_(compression_level_5).txt
/usr/local/lib/deadbeef/convpresets/MP3_CBR_320_Kbps_(Lame).txt
/usr/local/lib/deadbeef/convpresets/MP3_VBR_192Kbps_(Lame).txt
/usr/local/lib/deadbeef/convpresets/Ogg_Vorbis_(-q_5).txt
/usr/local/share/vim/vim82/lang/menu_chinese(gb)_gb.936.vim
/usr/local/share/vim/vim82/lang/menu_chinese(taiwan)_taiwan.950.vim
/usr/local/share/mypaint-data/1.0/brushes/kaerhon_v1/smudge_ink(0.7)_sm.myb
/usr/local/share/mypaint-data/1.0/brushes/kaerhon_v1/smudge_ink(0.7)_sm_prev.png
/usr/local/lib/python3.6/site-packages/setuptools/script (dev).tmpl
/usr/local/lib/python2.7/site-packages/setuptools-39.0.1-py2.7.egg/setuptools/script (dev).tmpl
usr/local/share/vim/vim72/lang/menu_chinese(gb)_gb.936.vim
usr/local/share/vim/vim72/lang/menu_chinese(taiwan)_taiwan.950.vim
usr/local/share/gtk-doc/html/libxfce4panel-1.0/libxfce4panel-Panel-Plugin-Register-Macros-(4.6-Style).html
tc@E310:~/Scripting/Provides$
--- End code ---
--- Quote from: polikuo on November 24, 2024, 02:26:19 AM --- ... The only thing that needs adjusting is the leading "^" ...
--- End quote ---
There is no leading ^ in this type of search. All filenames include a path, so
to anchor the beginning, just add a leading slash.
Let's say you're looking for program called apps:
--- Code: ---tc@E310:~/Scripting/Provides$ ./provides.sh apps | wc -l
95
--- End code ---
That's way too many. To narrow the search, you add an anchor:
--- Code: ---tc@E310:~/Scripting/Provides$ ./provides.sh /apps | wc -l
78
--- End code ---
That narrowed it some, but you know it's a program, so you extend the anchor:
--- Code: ---tc@E310:~/Scripting/Provides$ ./provides.sh bin/apps
Xprogs.tcz
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version