[TriLUG] missing packages help

Alan Porter porter at trilug.org
Sun Sep 17 14:59:37 EDT 2006


> i was trying to to show all the files that begain with lib. i was 
> looking to see if i could find something similar to the libobdcinst

You were trying to show all of the PACKAGES that started with "lib".  
You were not trying to show all of the FILES IN THE CURRENT DIRECTORY 
that started with "lib".

It's a subtle, but very important distinction.  Once you figure out what 
the shell is doing with what you type, things tend to make a lot more sense.

>> When there are no files that begin with "lib", the shell can do one 
>> of two things:
>> (1) replace "lib*" with ""
>> (2) keep the "lib*"
>
> im confused about option 1)... but thats what they made man pages for, 
> ill have to look into that later.

The shell replaces wildcards before it calls the command.  Here's some 
examples.

$ ls
(expand wildcards, no wildcards, so just do "ls")
resume.pdf
song1.mp3
song2.mp3

$ ls *.mp3
(expand wildcards, so "ls song1.mp3 song2.mp3")
song1.mp3
song2.mp3

$ shopt -s nullglob ; ls *.doc
(expand wildcards, no matches, nullglob is set, so "ls ")
resume.pdf
song1.mp3
song2.mp3

$ shopt -u nullglob ; ls *.doc
(expand wildcards, no matches, nullglob is not set, so "ls *.doc")
no such file "*.doc"

This is what I meant by "Each of these may seem intuitive under 
different circumstances".  In this case, it seems more intuitive to 
leave nullglob unset and get an error message from "ls".  "ls" had no 
idea what to do when it was passed "*.doc".  It was looking for a file 
called, literally, "star-dot-doc".

If you'd like to see a case there it's more intuitive to have nullglob 
set, try "touch *.ogg" in an empty directory.  What did it do?  If 
nullglob was set, it would create a file called "*.ogg".  Not what you 
thought, was it?  The "touch" command simply did the best it could with 
what the shell told it to do.  The shell tried to expand the wildcard, 
failed, and passed the wildcard on to "touch".  The only thing "touch" 
knew how to do was create an empty file called "star-dot-ogg".

For people who come from the DOS world, it might seem weird for the 
shell to do the filename wildcard expansion.  DOS programmers typically 
had to do that themselves.  So each DOS program tended to handle 
wildcard expansion a little differently.  Ugh.

An exercise for the reader... which is more conservative when using "rm 
*.pdf", setting nullglob or not?  This is why I leave nullglob OFF (I 
set it with a "shopt -u nullglob" in my .bashrc).

Anyway, it sounds like you're on your way with the libraries.  I hope 
this little lesson in bash and other unix shells has not been too much 
of a diversion.  And I hope it sheds some light on what might otherwise 
seem like unpredictable behavior.

Alan




.










More information about the TriLUG mailing list