Shortening a long if/test string comparison

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











up vote
0
down vote

favorite












I am comparing multiple strings in bash. Currently I have a script that looks like this:



 if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory


How can I shorten this?







share|improve this question


























    up vote
    0
    down vote

    favorite












    I am comparing multiple strings in bash. Currently I have a script that looks like this:



     if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory


    How can I shorten this?







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am comparing multiple strings in bash. Currently I have a script that looks like this:



       if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory


      How can I shorten this?







      share|improve this question














      I am comparing multiple strings in bash. Currently I have a script that looks like this:



       if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory


      How can I shorten this?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 10 '17 at 15:39









      Jeff Schaller

      32k848109




      32k848109










      asked Dec 6 '17 at 7:36









      scroobius

      33




      33




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Ended up with something like this:



          [[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]





          share|improve this answer


















          • 1




            I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
            – ilkkachu
            Dec 6 '17 at 8:09










          • @ilkkachu okay thanks edited the answer
            – scroobius
            Dec 7 '17 at 4:07










          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%2f409119%2fshortening-a-long-if-test-string-comparison%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          Ended up with something like this:



          [[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]





          share|improve this answer


















          • 1




            I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
            – ilkkachu
            Dec 6 '17 at 8:09










          • @ilkkachu okay thanks edited the answer
            – scroobius
            Dec 7 '17 at 4:07














          up vote
          0
          down vote



          accepted










          Ended up with something like this:



          [[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]





          share|improve this answer


















          • 1




            I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
            – ilkkachu
            Dec 6 '17 at 8:09










          • @ilkkachu okay thanks edited the answer
            – scroobius
            Dec 7 '17 at 4:07












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          Ended up with something like this:



          [[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]





          share|improve this answer














          Ended up with something like this:



          [[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 7 '17 at 4:08

























          answered Dec 6 '17 at 7:59









          scroobius

          33




          33







          • 1




            I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
            – ilkkachu
            Dec 6 '17 at 8:09










          • @ilkkachu okay thanks edited the answer
            – scroobius
            Dec 7 '17 at 4:07












          • 1




            I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
            – ilkkachu
            Dec 6 '17 at 8:09










          • @ilkkachu okay thanks edited the answer
            – scroobius
            Dec 7 '17 at 4:07







          1




          1




          I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
          – ilkkachu
          Dec 6 '17 at 8:09




          I don't think you need the quotes on the right hand side (there's nothing special in A-C to quote, it's not a character class without the brackets). @(foo|bar) to match exactly once, with + it'll match e.g. A-CJ-L
          – ilkkachu
          Dec 6 '17 at 8:09












          @ilkkachu okay thanks edited the answer
          – scroobius
          Dec 7 '17 at 4:07




          @ilkkachu okay thanks edited the answer
          – scroobius
          Dec 7 '17 at 4:07

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409119%2fshortening-a-long-if-test-string-comparison%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?