How does “$” work in “apt-cache search something$”

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I understand that:



$ apt-cache search package_name


will search for matches in names and descriptions.



But how does this work?



$ apt-cache search package_name$


For example,



$ apt-cache search desktop


will produce a list of names and short descriptions of packages that have "desktop" anywhere in the name or description.



Then, if I understand correctly,



$ apt-cache search desktop$


should produce a subset in which "desktop" is the last word either in the name or in any line in the description.



But I found one example, xjig, which shows up with apt-cache search desktop but doesn't show up with apt-cache search desktop$ even though the description according to apt-cache show xjig has "desktop" in the second-last line of the description:




Description-en: An X11 jigsaw puzzle

xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen

as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut

into pieces. The goal (as with any jigsaw puzzle) is to reassemble the

original picture.

.

Tiles may be freely rotated by use of the mouse, flipped (for

double-sided puzzles) and even shown as shaped windows on the desktop

(fast machine/video card recommended for the latter!). An example image

is provided in /usr/share/games/xjig .




So why is xjig not included in the output of apt-cache search desktop$?










share|improve this question



























    up vote
    3
    down vote

    favorite












    I understand that:



    $ apt-cache search package_name


    will search for matches in names and descriptions.



    But how does this work?



    $ apt-cache search package_name$


    For example,



    $ apt-cache search desktop


    will produce a list of names and short descriptions of packages that have "desktop" anywhere in the name or description.



    Then, if I understand correctly,



    $ apt-cache search desktop$


    should produce a subset in which "desktop" is the last word either in the name or in any line in the description.



    But I found one example, xjig, which shows up with apt-cache search desktop but doesn't show up with apt-cache search desktop$ even though the description according to apt-cache show xjig has "desktop" in the second-last line of the description:




    Description-en: An X11 jigsaw puzzle

    xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen

    as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut

    into pieces. The goal (as with any jigsaw puzzle) is to reassemble the

    original picture.

    .

    Tiles may be freely rotated by use of the mouse, flipped (for

    double-sided puzzles) and even shown as shaped windows on the desktop

    (fast machine/video card recommended for the latter!). An example image

    is provided in /usr/share/games/xjig .




    So why is xjig not included in the output of apt-cache search desktop$?










    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I understand that:



      $ apt-cache search package_name


      will search for matches in names and descriptions.



      But how does this work?



      $ apt-cache search package_name$


      For example,



      $ apt-cache search desktop


      will produce a list of names and short descriptions of packages that have "desktop" anywhere in the name or description.



      Then, if I understand correctly,



      $ apt-cache search desktop$


      should produce a subset in which "desktop" is the last word either in the name or in any line in the description.



      But I found one example, xjig, which shows up with apt-cache search desktop but doesn't show up with apt-cache search desktop$ even though the description according to apt-cache show xjig has "desktop" in the second-last line of the description:




      Description-en: An X11 jigsaw puzzle

      xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen

      as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut

      into pieces. The goal (as with any jigsaw puzzle) is to reassemble the

      original picture.

      .

      Tiles may be freely rotated by use of the mouse, flipped (for

      double-sided puzzles) and even shown as shaped windows on the desktop

      (fast machine/video card recommended for the latter!). An example image

      is provided in /usr/share/games/xjig .




      So why is xjig not included in the output of apt-cache search desktop$?










      share|improve this question















      I understand that:



      $ apt-cache search package_name


      will search for matches in names and descriptions.



      But how does this work?



      $ apt-cache search package_name$


      For example,



      $ apt-cache search desktop


      will produce a list of names and short descriptions of packages that have "desktop" anywhere in the name or description.



      Then, if I understand correctly,



      $ apt-cache search desktop$


      should produce a subset in which "desktop" is the last word either in the name or in any line in the description.



      But I found one example, xjig, which shows up with apt-cache search desktop but doesn't show up with apt-cache search desktop$ even though the description according to apt-cache show xjig has "desktop" in the second-last line of the description:




      Description-en: An X11 jigsaw puzzle

      xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen

      as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut

      into pieces. The goal (as with any jigsaw puzzle) is to reassemble the

      original picture.

      .

      Tiles may be freely rotated by use of the mouse, flipped (for

      double-sided puzzles) and even shown as shaped windows on the desktop

      (fast machine/video card recommended for the latter!). An example image

      is provided in /usr/share/games/xjig .




      So why is xjig not included in the output of apt-cache search desktop$?







      apt regular-expression






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 5 mins ago









      GAD3R

      23.6k164899




      23.6k164899










      asked Jan 28 '14 at 6:02







      user15760



























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          From the apt-cache man page:



          search regex...
          search performs a full text search on all available package lists for the
          POSIX regex pattern given, see regex(7). It searches the package names
          and the descriptions for an occurrence of the regular expression and
          prints out the package name and the short description, including virtual
          package names. If --full is given then output identical to show is
          produced for each matched package, and if --names-only is given then the
          long description is not searched, only the package name is.

          Separate arguments can be used to specify multiple search patterns that
          are and'ed together.


          Notice it states regex(7). So when you tell apt-cache to search for something you're providing it a regular expression. The $ in a regex means that you want to match, anchored to the end of strings.



          So if we're gave the value desktop$ we'd only match strings where desktop was at the end of strings such as:



          • this is a desktop

          • this is a very long string with desktop

          But it wouldn't match strings such as:



          • this is desktop in the window

          • this is another desktop in the window

          In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value.



          Example



          Here's xjig's description.



          Description-en: An X11 jigsaw puzzle
          xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen
          as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut
          into pieces. The goal (as with any jigsaw puzzle) is to reassemble the
          original picture.
          .
          Tiles may be freely rotated by use of the mouse, flipped (for
          double-sided puzzles) and even shown as shaped windows on the desktop
          (fast machine/video card recommended for the latter!). An example image
          is provided in /usr/share/games/xjig .


          If I search for all strings that end with xjig .$.



          $ apt-cache search 'xjig .$'
          xjig - An X11 jigsaw puzzle


          Remember that the value for the description is just a long string that is wrapped at that point, so though "desktop" is at the end a line, it isn't actually at the end of the description's value.



          Alternative



          Given you're looking for the word desktop you could look for the string with either spaces on either side (s), or word boundaries (b).



          $ apt-cache search 'sdesktops' | grep xjig
          xjig - An X11 jigsaw puzzle

          $ apt-cache search 'bdesktopb' | grep xjig
          xjig - An X11 jigsaw puzzle


          Understanding regex anchors



          Perhaps using grep to see what an anchor does in a regex would help.



          desktop not at the end



          $ echo "this is a desktop string" | grep "desktop$"
          $


          desktop at the end



          $ echo "this is a desktop" | grep "desktop$"
          this is a desktop


          The compliment to $ for anchoring matches to the end of strings, is the ^ for anchoring matches to the beginning.



          desktop not at beginning



          $ echo "this is a desktop" | grep "^desktop"
          $


          desktop at beginning



          $ echo "desktop this is a desktop" | grep "^desktop"
          desktop this is a desktop





          share|improve this answer






















          • I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
            – user15760
            Jan 28 '14 at 7:16










          • @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
            – slm♦
            Jan 28 '14 at 7:19










          • Okay, but why the space after xjigand before the period?
            – user15760
            Jan 28 '14 at 7:27






          • 1




            @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
            – slm♦
            Jan 28 '14 at 7:29


















          up vote
          3
          down vote













          The description field is a multi-line field but $ in the regexp, means the end of the field, not the end of each line of the field. So, if you want to search for desktop at the end of a line or at the end of the field, you need:



          apt-cache search 'desktop(
          |$)'


          Or with the ksh93 $'...' quotes (also found in zsh and bash) allowing x escape sequences:



          apt-cache search $'desktop(n|$)'


          Also note that . does match a newline character. Written in perl, that would be:



          print "$name - $summary" if 
          $name =~ qr$resi ||
          $description =~ qr$resi;


          (except they are not perl regexps of course)






          share|improve this answer






















          • You might want to explain the $'' notation. Most ppl are not familiar with it.
            – slm♦
            Jan 28 '14 at 7:22










          • Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
            – user15760
            Jan 28 '14 at 7:24










          • @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
            – Stéphane Chazelas
            Jan 28 '14 at 7:27










          • @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
            – slm♦
            Jan 28 '14 at 7:32











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f111255%2fhow-does-work-in-apt-cache-search-something%23new-answer', 'question_page');

          );

          Post as a guest





























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          From the apt-cache man page:



          search regex...
          search performs a full text search on all available package lists for the
          POSIX regex pattern given, see regex(7). It searches the package names
          and the descriptions for an occurrence of the regular expression and
          prints out the package name and the short description, including virtual
          package names. If --full is given then output identical to show is
          produced for each matched package, and if --names-only is given then the
          long description is not searched, only the package name is.

          Separate arguments can be used to specify multiple search patterns that
          are and'ed together.


          Notice it states regex(7). So when you tell apt-cache to search for something you're providing it a regular expression. The $ in a regex means that you want to match, anchored to the end of strings.



          So if we're gave the value desktop$ we'd only match strings where desktop was at the end of strings such as:



          • this is a desktop

          • this is a very long string with desktop

          But it wouldn't match strings such as:



          • this is desktop in the window

          • this is another desktop in the window

          In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value.



          Example



          Here's xjig's description.



          Description-en: An X11 jigsaw puzzle
          xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen
          as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut
          into pieces. The goal (as with any jigsaw puzzle) is to reassemble the
          original picture.
          .
          Tiles may be freely rotated by use of the mouse, flipped (for
          double-sided puzzles) and even shown as shaped windows on the desktop
          (fast machine/video card recommended for the latter!). An example image
          is provided in /usr/share/games/xjig .


          If I search for all strings that end with xjig .$.



          $ apt-cache search 'xjig .$'
          xjig - An X11 jigsaw puzzle


          Remember that the value for the description is just a long string that is wrapped at that point, so though "desktop" is at the end a line, it isn't actually at the end of the description's value.



          Alternative



          Given you're looking for the word desktop you could look for the string with either spaces on either side (s), or word boundaries (b).



          $ apt-cache search 'sdesktops' | grep xjig
          xjig - An X11 jigsaw puzzle

          $ apt-cache search 'bdesktopb' | grep xjig
          xjig - An X11 jigsaw puzzle


          Understanding regex anchors



          Perhaps using grep to see what an anchor does in a regex would help.



          desktop not at the end



          $ echo "this is a desktop string" | grep "desktop$"
          $


          desktop at the end



          $ echo "this is a desktop" | grep "desktop$"
          this is a desktop


          The compliment to $ for anchoring matches to the end of strings, is the ^ for anchoring matches to the beginning.



          desktop not at beginning



          $ echo "this is a desktop" | grep "^desktop"
          $


          desktop at beginning



          $ echo "desktop this is a desktop" | grep "^desktop"
          desktop this is a desktop





          share|improve this answer






















          • I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
            – user15760
            Jan 28 '14 at 7:16










          • @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
            – slm♦
            Jan 28 '14 at 7:19










          • Okay, but why the space after xjigand before the period?
            – user15760
            Jan 28 '14 at 7:27






          • 1




            @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
            – slm♦
            Jan 28 '14 at 7:29















          up vote
          3
          down vote



          accepted










          From the apt-cache man page:



          search regex...
          search performs a full text search on all available package lists for the
          POSIX regex pattern given, see regex(7). It searches the package names
          and the descriptions for an occurrence of the regular expression and
          prints out the package name and the short description, including virtual
          package names. If --full is given then output identical to show is
          produced for each matched package, and if --names-only is given then the
          long description is not searched, only the package name is.

          Separate arguments can be used to specify multiple search patterns that
          are and'ed together.


          Notice it states regex(7). So when you tell apt-cache to search for something you're providing it a regular expression. The $ in a regex means that you want to match, anchored to the end of strings.



          So if we're gave the value desktop$ we'd only match strings where desktop was at the end of strings such as:



          • this is a desktop

          • this is a very long string with desktop

          But it wouldn't match strings such as:



          • this is desktop in the window

          • this is another desktop in the window

          In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value.



          Example



          Here's xjig's description.



          Description-en: An X11 jigsaw puzzle
          xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen
          as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut
          into pieces. The goal (as with any jigsaw puzzle) is to reassemble the
          original picture.
          .
          Tiles may be freely rotated by use of the mouse, flipped (for
          double-sided puzzles) and even shown as shaped windows on the desktop
          (fast machine/video card recommended for the latter!). An example image
          is provided in /usr/share/games/xjig .


          If I search for all strings that end with xjig .$.



          $ apt-cache search 'xjig .$'
          xjig - An X11 jigsaw puzzle


          Remember that the value for the description is just a long string that is wrapped at that point, so though "desktop" is at the end a line, it isn't actually at the end of the description's value.



          Alternative



          Given you're looking for the word desktop you could look for the string with either spaces on either side (s), or word boundaries (b).



          $ apt-cache search 'sdesktops' | grep xjig
          xjig - An X11 jigsaw puzzle

          $ apt-cache search 'bdesktopb' | grep xjig
          xjig - An X11 jigsaw puzzle


          Understanding regex anchors



          Perhaps using grep to see what an anchor does in a regex would help.



          desktop not at the end



          $ echo "this is a desktop string" | grep "desktop$"
          $


          desktop at the end



          $ echo "this is a desktop" | grep "desktop$"
          this is a desktop


          The compliment to $ for anchoring matches to the end of strings, is the ^ for anchoring matches to the beginning.



          desktop not at beginning



          $ echo "this is a desktop" | grep "^desktop"
          $


          desktop at beginning



          $ echo "desktop this is a desktop" | grep "^desktop"
          desktop this is a desktop





          share|improve this answer






















          • I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
            – user15760
            Jan 28 '14 at 7:16










          • @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
            – slm♦
            Jan 28 '14 at 7:19










          • Okay, but why the space after xjigand before the period?
            – user15760
            Jan 28 '14 at 7:27






          • 1




            @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
            – slm♦
            Jan 28 '14 at 7:29













          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          From the apt-cache man page:



          search regex...
          search performs a full text search on all available package lists for the
          POSIX regex pattern given, see regex(7). It searches the package names
          and the descriptions for an occurrence of the regular expression and
          prints out the package name and the short description, including virtual
          package names. If --full is given then output identical to show is
          produced for each matched package, and if --names-only is given then the
          long description is not searched, only the package name is.

          Separate arguments can be used to specify multiple search patterns that
          are and'ed together.


          Notice it states regex(7). So when you tell apt-cache to search for something you're providing it a regular expression. The $ in a regex means that you want to match, anchored to the end of strings.



          So if we're gave the value desktop$ we'd only match strings where desktop was at the end of strings such as:



          • this is a desktop

          • this is a very long string with desktop

          But it wouldn't match strings such as:



          • this is desktop in the window

          • this is another desktop in the window

          In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value.



          Example



          Here's xjig's description.



          Description-en: An X11 jigsaw puzzle
          xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen
          as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut
          into pieces. The goal (as with any jigsaw puzzle) is to reassemble the
          original picture.
          .
          Tiles may be freely rotated by use of the mouse, flipped (for
          double-sided puzzles) and even shown as shaped windows on the desktop
          (fast machine/video card recommended for the latter!). An example image
          is provided in /usr/share/games/xjig .


          If I search for all strings that end with xjig .$.



          $ apt-cache search 'xjig .$'
          xjig - An X11 jigsaw puzzle


          Remember that the value for the description is just a long string that is wrapped at that point, so though "desktop" is at the end a line, it isn't actually at the end of the description's value.



          Alternative



          Given you're looking for the word desktop you could look for the string with either spaces on either side (s), or word boundaries (b).



          $ apt-cache search 'sdesktops' | grep xjig
          xjig - An X11 jigsaw puzzle

          $ apt-cache search 'bdesktopb' | grep xjig
          xjig - An X11 jigsaw puzzle


          Understanding regex anchors



          Perhaps using grep to see what an anchor does in a regex would help.



          desktop not at the end



          $ echo "this is a desktop string" | grep "desktop$"
          $


          desktop at the end



          $ echo "this is a desktop" | grep "desktop$"
          this is a desktop


          The compliment to $ for anchoring matches to the end of strings, is the ^ for anchoring matches to the beginning.



          desktop not at beginning



          $ echo "this is a desktop" | grep "^desktop"
          $


          desktop at beginning



          $ echo "desktop this is a desktop" | grep "^desktop"
          desktop this is a desktop





          share|improve this answer














          From the apt-cache man page:



          search regex...
          search performs a full text search on all available package lists for the
          POSIX regex pattern given, see regex(7). It searches the package names
          and the descriptions for an occurrence of the regular expression and
          prints out the package name and the short description, including virtual
          package names. If --full is given then output identical to show is
          produced for each matched package, and if --names-only is given then the
          long description is not searched, only the package name is.

          Separate arguments can be used to specify multiple search patterns that
          are and'ed together.


          Notice it states regex(7). So when you tell apt-cache to search for something you're providing it a regular expression. The $ in a regex means that you want to match, anchored to the end of strings.



          So if we're gave the value desktop$ we'd only match strings where desktop was at the end of strings such as:



          • this is a desktop

          • this is a very long string with desktop

          But it wouldn't match strings such as:



          • this is desktop in the window

          • this is another desktop in the window

          In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value.



          Example



          Here's xjig's description.



          Description-en: An X11 jigsaw puzzle
          xjig is a puzzle that tries to replicate a jigsaw puzzle on the screen
          as closely as possible. Any GIF, JPEG or PPM image may be loaded and cut
          into pieces. The goal (as with any jigsaw puzzle) is to reassemble the
          original picture.
          .
          Tiles may be freely rotated by use of the mouse, flipped (for
          double-sided puzzles) and even shown as shaped windows on the desktop
          (fast machine/video card recommended for the latter!). An example image
          is provided in /usr/share/games/xjig .


          If I search for all strings that end with xjig .$.



          $ apt-cache search 'xjig .$'
          xjig - An X11 jigsaw puzzle


          Remember that the value for the description is just a long string that is wrapped at that point, so though "desktop" is at the end a line, it isn't actually at the end of the description's value.



          Alternative



          Given you're looking for the word desktop you could look for the string with either spaces on either side (s), or word boundaries (b).



          $ apt-cache search 'sdesktops' | grep xjig
          xjig - An X11 jigsaw puzzle

          $ apt-cache search 'bdesktopb' | grep xjig
          xjig - An X11 jigsaw puzzle


          Understanding regex anchors



          Perhaps using grep to see what an anchor does in a regex would help.



          desktop not at the end



          $ echo "this is a desktop string" | grep "desktop$"
          $


          desktop at the end



          $ echo "this is a desktop" | grep "desktop$"
          this is a desktop


          The compliment to $ for anchoring matches to the end of strings, is the ^ for anchoring matches to the beginning.



          desktop not at beginning



          $ echo "this is a desktop" | grep "^desktop"
          $


          desktop at beginning



          $ echo "desktop this is a desktop" | grep "^desktop"
          desktop this is a desktop






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 28 '14 at 7:29

























          answered Jan 28 '14 at 7:02









          slm♦

          241k66501669




          241k66501669











          • I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
            – user15760
            Jan 28 '14 at 7:16










          • @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
            – slm♦
            Jan 28 '14 at 7:19










          • Okay, but why the space after xjigand before the period?
            – user15760
            Jan 28 '14 at 7:27






          • 1




            @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
            – slm♦
            Jan 28 '14 at 7:29

















          • I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
            – user15760
            Jan 28 '14 at 7:16










          • @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
            – slm♦
            Jan 28 '14 at 7:19










          • Okay, but why the space after xjigand before the period?
            – user15760
            Jan 28 '14 at 7:27






          • 1




            @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
            – slm♦
            Jan 28 '14 at 7:29
















          I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
          – user15760
          Jan 28 '14 at 7:16




          I am able to understand "In your case the string desktop in xjig's description, though at the end of a line in the description, is not at the end of the description field's value." I think that would explain my confusion. But why did you give apt-cache search xjig .$ as an example? That has me confused again. Doesn't it mean we're now searching for two terms, xjig and .$?
          – user15760
          Jan 28 '14 at 7:16












          @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
          – slm♦
          Jan 28 '14 at 7:19




          @vasa1 - no we're looking for a string "xjig ." but only ones that are at the end of the strings we're attempting to match. Remember we're quoting the arguments to apt-cache search in single quotes, so it's a single argument we're looking for.
          – slm♦
          Jan 28 '14 at 7:19












          Okay, but why the space after xjigand before the period?
          – user15760
          Jan 28 '14 at 7:27




          Okay, but why the space after xjigand before the period?
          – user15760
          Jan 28 '14 at 7:27




          1




          1




          @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
          – slm♦
          Jan 28 '14 at 7:29





          @vasa1 - that's how the description shows up for xjig. No other reason than that. Run this apt-cache show xjig and look at how the Description field shows up.
          – slm♦
          Jan 28 '14 at 7:29













          up vote
          3
          down vote













          The description field is a multi-line field but $ in the regexp, means the end of the field, not the end of each line of the field. So, if you want to search for desktop at the end of a line or at the end of the field, you need:



          apt-cache search 'desktop(
          |$)'


          Or with the ksh93 $'...' quotes (also found in zsh and bash) allowing x escape sequences:



          apt-cache search $'desktop(n|$)'


          Also note that . does match a newline character. Written in perl, that would be:



          print "$name - $summary" if 
          $name =~ qr$resi ||
          $description =~ qr$resi;


          (except they are not perl regexps of course)






          share|improve this answer






















          • You might want to explain the $'' notation. Most ppl are not familiar with it.
            – slm♦
            Jan 28 '14 at 7:22










          • Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
            – user15760
            Jan 28 '14 at 7:24










          • @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
            – Stéphane Chazelas
            Jan 28 '14 at 7:27










          • @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
            – slm♦
            Jan 28 '14 at 7:32















          up vote
          3
          down vote













          The description field is a multi-line field but $ in the regexp, means the end of the field, not the end of each line of the field. So, if you want to search for desktop at the end of a line or at the end of the field, you need:



          apt-cache search 'desktop(
          |$)'


          Or with the ksh93 $'...' quotes (also found in zsh and bash) allowing x escape sequences:



          apt-cache search $'desktop(n|$)'


          Also note that . does match a newline character. Written in perl, that would be:



          print "$name - $summary" if 
          $name =~ qr$resi ||
          $description =~ qr$resi;


          (except they are not perl regexps of course)






          share|improve this answer






















          • You might want to explain the $'' notation. Most ppl are not familiar with it.
            – slm♦
            Jan 28 '14 at 7:22










          • Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
            – user15760
            Jan 28 '14 at 7:24










          • @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
            – Stéphane Chazelas
            Jan 28 '14 at 7:27










          • @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
            – slm♦
            Jan 28 '14 at 7:32













          up vote
          3
          down vote










          up vote
          3
          down vote









          The description field is a multi-line field but $ in the regexp, means the end of the field, not the end of each line of the field. So, if you want to search for desktop at the end of a line or at the end of the field, you need:



          apt-cache search 'desktop(
          |$)'


          Or with the ksh93 $'...' quotes (also found in zsh and bash) allowing x escape sequences:



          apt-cache search $'desktop(n|$)'


          Also note that . does match a newline character. Written in perl, that would be:



          print "$name - $summary" if 
          $name =~ qr$resi ||
          $description =~ qr$resi;


          (except they are not perl regexps of course)






          share|improve this answer














          The description field is a multi-line field but $ in the regexp, means the end of the field, not the end of each line of the field. So, if you want to search for desktop at the end of a line or at the end of the field, you need:



          apt-cache search 'desktop(
          |$)'


          Or with the ksh93 $'...' quotes (also found in zsh and bash) allowing x escape sequences:



          apt-cache search $'desktop(n|$)'


          Also note that . does match a newline character. Written in perl, that would be:



          print "$name - $summary" if 
          $name =~ qr$resi ||
          $description =~ qr$resi;


          (except they are not perl regexps of course)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 28 '14 at 7:38

























          answered Jan 28 '14 at 7:19









          Stéphane Chazelas

          289k54535874




          289k54535874











          • You might want to explain the $'' notation. Most ppl are not familiar with it.
            – slm♦
            Jan 28 '14 at 7:22










          • Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
            – user15760
            Jan 28 '14 at 7:24










          • @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
            – Stéphane Chazelas
            Jan 28 '14 at 7:27










          • @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
            – slm♦
            Jan 28 '14 at 7:32

















          • You might want to explain the $'' notation. Most ppl are not familiar with it.
            – slm♦
            Jan 28 '14 at 7:22










          • Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
            – user15760
            Jan 28 '14 at 7:24










          • @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
            – Stéphane Chazelas
            Jan 28 '14 at 7:27










          • @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
            – slm♦
            Jan 28 '14 at 7:32
















          You might want to explain the $'' notation. Most ppl are not familiar with it.
          – slm♦
          Jan 28 '14 at 7:22




          You might want to explain the $'' notation. Most ppl are not familiar with it.
          – slm♦
          Jan 28 '14 at 7:22












          Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
          – user15760
          Jan 28 '14 at 7:24




          Yes, I was about to ask that because apt-cache search 'desktop(n|$)' apparently works as well.
          – user15760
          Jan 28 '14 at 7:24












          @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
          – Stéphane Chazelas
          Jan 28 '14 at 7:27




          @vasa1. Hmmm. Weird, 'desktop(n|$)' seems to work indeed, but not 'desktopn' nor 'desktop(n)'. I don't know why.
          – Stéphane Chazelas
          Jan 28 '14 at 7:27












          @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
          – slm♦
          Jan 28 '14 at 7:32





          @StephaneChazelas - yeah I noticed the 'desktopn' didn't work either. I left it out of my answer as to not confuse the situation further. That's why I went with the b approach.
          – slm♦
          Jan 28 '14 at 7:32


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f111255%2fhow-does-work-in-apt-cache-search-something%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)