tcsh: search entire array for a variableHow to print whole array in tcshtcsh: i-search-back character...

Handling Disruptive Student on the Autistic Spectrum

Can RMSE and MAE have the same value?

How do we calculate energy of food?

Was the Boeing 2707 design flawed?

Is MOSFET active device?

Are modern clipless shoes and pedals that much better than toe clips and straps?

Compelling story with the world as a villain

Network helper class with retry logic on failure

Read file lines into shell line separated by space

How to find out the average duration of the peer-review process for a given journal?

Why in most German places is the church the tallest building?

Can I get temporary health insurance while moving to the US?

Architectural feasibility of a tiered circular stone keep

Was it ever possible to target a zone?

Two questions about typesetting a Roman missal

What verb is かまされる?

Prevent use of CNAME Record for Untrusted Domain

Why does Windows store Wi-Fi passwords in a reversable format?

Uri tokenizer as a simple state machine

Sum ergo cogito?

Is "The life is beautiful" incorrect or just very non-idiomatic?

Why is there a difference between predicting on Validation set and Test set?

Why is 1. d4 Nf6 2. c4 e6 3. Bg5 almost never played?

Algorithms vs LP or MIP



tcsh: search entire array for a variable


How to print whole array in tcshtcsh: i-search-back character glitchHow to search empty alternation with tcshWhat does dollar underscore mean in tcsh? $_Why does “ps -p proc1 proc2 proc3” show “-csh”, “-tcsh”, and “-/bin/tcsh”, whereas “ps -p proc[n]” individually all say “tcsh”?tcsh variable weirdnessHow many elements can an array store in unix script?What is the rationale behind $array not expanding the whole array in ksh and bash?Assigning / evaluating concatenated variables in tcsherror while using sed in tcsh alias






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I am modifying a suite of scripts written in tcsh. Unfortunately, these scripts can't be rewritten because the program they interface with is also written in tcsh. I just want to get out of the way the idea that if I could rewrite these in BASH or literally any other language, I would.



As part of these scripts many of our variables are saved in arrays. My question is: Is there a way in tcsh where you can query if the content of a variable is present in an array (regardless of its position in the array) without using loops?



For example, I have the following array of valid ROI names:



set shortROI = {"lAmy_","mAmy_","A32p_","A32sg_"}


When the user executes the script they have an option to use a flag to say they want to redo processing for one or more specific ROIs from the options above. So like, if the flag is -remake_ROI, as part of calling the script they could add -remake_ROI lAmy or -remake_ROI lAmy A32p_ to remake those ROIs only. I have a very large while loop currently processing all possible flags but the section relevant here looks like this:



set ac = 1
set redo_rois = 0
set roi_proc_list =

while ( $ac <= $#argv )
foreach roi_opt ( $shortROI )
if ( "$argv[$ac]" == $roi_opt )
@ redo_rois ++
set roi_proc_list = ( $roi_proc_list $roi_opts )
endif
end
@ ac ++
end


ac is the command line argument count, redo_rois is the number of ROIs to re-process and roi_proc_list is the actual list to redo. I was wondering instead of the many loops, if there was something like if ( "$argv[$ac]" == "$shortROI[*]" ) that would get the job done.



Thank anyone for their help.










share|improve this question







New contributor



chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    0















    I am modifying a suite of scripts written in tcsh. Unfortunately, these scripts can't be rewritten because the program they interface with is also written in tcsh. I just want to get out of the way the idea that if I could rewrite these in BASH or literally any other language, I would.



    As part of these scripts many of our variables are saved in arrays. My question is: Is there a way in tcsh where you can query if the content of a variable is present in an array (regardless of its position in the array) without using loops?



    For example, I have the following array of valid ROI names:



    set shortROI = {"lAmy_","mAmy_","A32p_","A32sg_"}


    When the user executes the script they have an option to use a flag to say they want to redo processing for one or more specific ROIs from the options above. So like, if the flag is -remake_ROI, as part of calling the script they could add -remake_ROI lAmy or -remake_ROI lAmy A32p_ to remake those ROIs only. I have a very large while loop currently processing all possible flags but the section relevant here looks like this:



    set ac = 1
    set redo_rois = 0
    set roi_proc_list =

    while ( $ac <= $#argv )
    foreach roi_opt ( $shortROI )
    if ( "$argv[$ac]" == $roi_opt )
    @ redo_rois ++
    set roi_proc_list = ( $roi_proc_list $roi_opts )
    endif
    end
    @ ac ++
    end


    ac is the command line argument count, redo_rois is the number of ROIs to re-process and roi_proc_list is the actual list to redo. I was wondering instead of the many loops, if there was something like if ( "$argv[$ac]" == "$shortROI[*]" ) that would get the job done.



    Thank anyone for their help.










    share|improve this question







    New contributor



    chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0












      0








      0








      I am modifying a suite of scripts written in tcsh. Unfortunately, these scripts can't be rewritten because the program they interface with is also written in tcsh. I just want to get out of the way the idea that if I could rewrite these in BASH or literally any other language, I would.



      As part of these scripts many of our variables are saved in arrays. My question is: Is there a way in tcsh where you can query if the content of a variable is present in an array (regardless of its position in the array) without using loops?



      For example, I have the following array of valid ROI names:



      set shortROI = {"lAmy_","mAmy_","A32p_","A32sg_"}


      When the user executes the script they have an option to use a flag to say they want to redo processing for one or more specific ROIs from the options above. So like, if the flag is -remake_ROI, as part of calling the script they could add -remake_ROI lAmy or -remake_ROI lAmy A32p_ to remake those ROIs only. I have a very large while loop currently processing all possible flags but the section relevant here looks like this:



      set ac = 1
      set redo_rois = 0
      set roi_proc_list =

      while ( $ac <= $#argv )
      foreach roi_opt ( $shortROI )
      if ( "$argv[$ac]" == $roi_opt )
      @ redo_rois ++
      set roi_proc_list = ( $roi_proc_list $roi_opts )
      endif
      end
      @ ac ++
      end


      ac is the command line argument count, redo_rois is the number of ROIs to re-process and roi_proc_list is the actual list to redo. I was wondering instead of the many loops, if there was something like if ( "$argv[$ac]" == "$shortROI[*]" ) that would get the job done.



      Thank anyone for their help.










      share|improve this question







      New contributor



      chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am modifying a suite of scripts written in tcsh. Unfortunately, these scripts can't be rewritten because the program they interface with is also written in tcsh. I just want to get out of the way the idea that if I could rewrite these in BASH or literally any other language, I would.



      As part of these scripts many of our variables are saved in arrays. My question is: Is there a way in tcsh where you can query if the content of a variable is present in an array (regardless of its position in the array) without using loops?



      For example, I have the following array of valid ROI names:



      set shortROI = {"lAmy_","mAmy_","A32p_","A32sg_"}


      When the user executes the script they have an option to use a flag to say they want to redo processing for one or more specific ROIs from the options above. So like, if the flag is -remake_ROI, as part of calling the script they could add -remake_ROI lAmy or -remake_ROI lAmy A32p_ to remake those ROIs only. I have a very large while loop currently processing all possible flags but the section relevant here looks like this:



      set ac = 1
      set redo_rois = 0
      set roi_proc_list =

      while ( $ac <= $#argv )
      foreach roi_opt ( $shortROI )
      if ( "$argv[$ac]" == $roi_opt )
      @ redo_rois ++
      set roi_proc_list = ( $roi_proc_list $roi_opts )
      endif
      end
      @ ac ++
      end


      ac is the command line argument count, redo_rois is the number of ROIs to re-process and roi_proc_list is the actual list to redo. I was wondering instead of the many loops, if there was something like if ( "$argv[$ac]" == "$shortROI[*]" ) that would get the job done.



      Thank anyone for their help.







      array tcsh csh






      share|improve this question







      New contributor



      chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked yesterday









      chainhomelowchainhomelow

      1




      1




      New contributor



      chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      chainhomelow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          1 Answer
          1






          active

          oldest

          votes


















          1















          if (" $shortROI " =~ *" $argv[$ac] "*)
          ...
          endif


          Example:



          set list = (foo bar baz)

          foreach a ($*)
          if(" $list " =~ *" $a "*) then
          echo "$a in list"
          else
          echo "$a NOT in list"
          endif
          end


          This may incorrectly return true if either the variable on the right side or any of the words from the list contain spaces. If you can decide on a character which cannot appear in either side (eg. @), you can replace the spaces with it in each word:



          foreach a ($*:q)
          if(" $list:q:gas/ /@/ " =~ *" $a:q:as/ /@/ "*) then
          ...





          share|improve this answer






























            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            chainhomelow is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f537164%2ftcsh-search-entire-array-for-a-variable%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1















            if (" $shortROI " =~ *" $argv[$ac] "*)
            ...
            endif


            Example:



            set list = (foo bar baz)

            foreach a ($*)
            if(" $list " =~ *" $a "*) then
            echo "$a in list"
            else
            echo "$a NOT in list"
            endif
            end


            This may incorrectly return true if either the variable on the right side or any of the words from the list contain spaces. If you can decide on a character which cannot appear in either side (eg. @), you can replace the spaces with it in each word:



            foreach a ($*:q)
            if(" $list:q:gas/ /@/ " =~ *" $a:q:as/ /@/ "*) then
            ...





            share|improve this answer
































              1















              if (" $shortROI " =~ *" $argv[$ac] "*)
              ...
              endif


              Example:



              set list = (foo bar baz)

              foreach a ($*)
              if(" $list " =~ *" $a "*) then
              echo "$a in list"
              else
              echo "$a NOT in list"
              endif
              end


              This may incorrectly return true if either the variable on the right side or any of the words from the list contain spaces. If you can decide on a character which cannot appear in either side (eg. @), you can replace the spaces with it in each word:



              foreach a ($*:q)
              if(" $list:q:gas/ /@/ " =~ *" $a:q:as/ /@/ "*) then
              ...





              share|improve this answer






























                1














                1










                1









                if (" $shortROI " =~ *" $argv[$ac] "*)
                ...
                endif


                Example:



                set list = (foo bar baz)

                foreach a ($*)
                if(" $list " =~ *" $a "*) then
                echo "$a in list"
                else
                echo "$a NOT in list"
                endif
                end


                This may incorrectly return true if either the variable on the right side or any of the words from the list contain spaces. If you can decide on a character which cannot appear in either side (eg. @), you can replace the spaces with it in each word:



                foreach a ($*:q)
                if(" $list:q:gas/ /@/ " =~ *" $a:q:as/ /@/ "*) then
                ...





                share|improve this answer















                if (" $shortROI " =~ *" $argv[$ac] "*)
                ...
                endif


                Example:



                set list = (foo bar baz)

                foreach a ($*)
                if(" $list " =~ *" $a "*) then
                echo "$a in list"
                else
                echo "$a NOT in list"
                endif
                end


                This may incorrectly return true if either the variable on the right side or any of the words from the list contain spaces. If you can decide on a character which cannot appear in either side (eg. @), you can replace the spaces with it in each word:



                foreach a ($*:q)
                if(" $list:q:gas/ /@/ " =~ *" $a:q:as/ /@/ "*) then
                ...






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 7 hours ago

























                answered 8 hours ago









                mosvymosvy

                16.1k2 gold badges20 silver badges51 bronze badges




                16.1k2 gold badges20 silver badges51 bronze badges

























                    chainhomelow is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    chainhomelow is a new contributor. Be nice, and check out our Code of Conduct.













                    chainhomelow is a new contributor. Be nice, and check out our Code of Conduct.












                    chainhomelow is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f537164%2ftcsh-search-entire-array-for-a-variable%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                    Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                    Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...