Compare two variables with a Shell script

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











up vote
1
down vote

favorite












I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:



I have a script that allows me to compare these variables:



FT_NBR1='?""'
FT_NBR2=rcrdmddd


My question is how can I pass the FT_NBRs variables to the script to execute the comparison in the terminal?



Thanks!







share|improve this question

























    up vote
    1
    down vote

    favorite












    I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:



    I have a script that allows me to compare these variables:



    FT_NBR1='?""'
    FT_NBR2=rcrdmddd


    My question is how can I pass the FT_NBRs variables to the script to execute the comparison in the terminal?



    Thanks!







    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:



      I have a script that allows me to compare these variables:



      FT_NBR1='?""'
      FT_NBR2=rcrdmddd


      My question is how can I pass the FT_NBRs variables to the script to execute the comparison in the terminal?



      Thanks!







      share|improve this question













      I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:



      I have a script that allows me to compare these variables:



      FT_NBR1='?""'
      FT_NBR2=rcrdmddd


      My question is how can I pass the FT_NBRs variables to the script to execute the comparison in the terminal?



      Thanks!









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 11 at 9:36
























      asked Jun 6 at 11:52









      Wizzardzz

      83




      83




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can export the variables using your shell, then they will be available in the script.



          Example script:



          #!/bin/bash --
          echo "$test"


          Export variable and run script:



          $ export test=something
          $ ./script
          something


          The way you are trying to assign values to variables will not work.



          FT_NBR1='?""'
          FT_NBR2=rcrdmddd


          FT_NBR2 is fine, but FT_NBR1 is not valid. Have a look a single vs double quotes and special character escaping.






          share|improve this answer




























            up vote
            0
            down vote













            You can pass environmental variables to a script with setting the variables just before. The variables will not be set in the current environment, which can be useful in some cases.



            script.sh:



            #!/bin/bash
            echo "var1: $var1"


            and then call it with



            $ var1=234 ./script.sh
            var1: 123
            $ echo "var1: $var1"
            var1:


            This works in bash. I don't know about general POSIX compability.






            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',
              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%2f448177%2fcompare-two-variables-with-a-shell-script%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
              1
              down vote



              accepted










              You can export the variables using your shell, then they will be available in the script.



              Example script:



              #!/bin/bash --
              echo "$test"


              Export variable and run script:



              $ export test=something
              $ ./script
              something


              The way you are trying to assign values to variables will not work.



              FT_NBR1='?""'
              FT_NBR2=rcrdmddd


              FT_NBR2 is fine, but FT_NBR1 is not valid. Have a look a single vs double quotes and special character escaping.






              share|improve this answer

























                up vote
                1
                down vote



                accepted










                You can export the variables using your shell, then they will be available in the script.



                Example script:



                #!/bin/bash --
                echo "$test"


                Export variable and run script:



                $ export test=something
                $ ./script
                something


                The way you are trying to assign values to variables will not work.



                FT_NBR1='?""'
                FT_NBR2=rcrdmddd


                FT_NBR2 is fine, but FT_NBR1 is not valid. Have a look a single vs double quotes and special character escaping.






                share|improve this answer























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  You can export the variables using your shell, then they will be available in the script.



                  Example script:



                  #!/bin/bash --
                  echo "$test"


                  Export variable and run script:



                  $ export test=something
                  $ ./script
                  something


                  The way you are trying to assign values to variables will not work.



                  FT_NBR1='?""'
                  FT_NBR2=rcrdmddd


                  FT_NBR2 is fine, but FT_NBR1 is not valid. Have a look a single vs double quotes and special character escaping.






                  share|improve this answer













                  You can export the variables using your shell, then they will be available in the script.



                  Example script:



                  #!/bin/bash --
                  echo "$test"


                  Export variable and run script:



                  $ export test=something
                  $ ./script
                  something


                  The way you are trying to assign values to variables will not work.



                  FT_NBR1='?""'
                  FT_NBR2=rcrdmddd


                  FT_NBR2 is fine, but FT_NBR1 is not valid. Have a look a single vs double quotes and special character escaping.







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Jun 6 at 13:21









                  rusty shackleford

                  1,135115




                  1,135115






















                      up vote
                      0
                      down vote













                      You can pass environmental variables to a script with setting the variables just before. The variables will not be set in the current environment, which can be useful in some cases.



                      script.sh:



                      #!/bin/bash
                      echo "var1: $var1"


                      and then call it with



                      $ var1=234 ./script.sh
                      var1: 123
                      $ echo "var1: $var1"
                      var1:


                      This works in bash. I don't know about general POSIX compability.






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        You can pass environmental variables to a script with setting the variables just before. The variables will not be set in the current environment, which can be useful in some cases.



                        script.sh:



                        #!/bin/bash
                        echo "var1: $var1"


                        and then call it with



                        $ var1=234 ./script.sh
                        var1: 123
                        $ echo "var1: $var1"
                        var1:


                        This works in bash. I don't know about general POSIX compability.






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can pass environmental variables to a script with setting the variables just before. The variables will not be set in the current environment, which can be useful in some cases.



                          script.sh:



                          #!/bin/bash
                          echo "var1: $var1"


                          and then call it with



                          $ var1=234 ./script.sh
                          var1: 123
                          $ echo "var1: $var1"
                          var1:


                          This works in bash. I don't know about general POSIX compability.






                          share|improve this answer













                          You can pass environmental variables to a script with setting the variables just before. The variables will not be set in the current environment, which can be useful in some cases.



                          script.sh:



                          #!/bin/bash
                          echo "var1: $var1"


                          and then call it with



                          $ var1=234 ./script.sh
                          var1: 123
                          $ echo "var1: $var1"
                          var1:


                          This works in bash. I don't know about general POSIX compability.







                          share|improve this answer













                          share|improve this answer



                          share|improve this answer











                          answered Jun 6 at 13:41









                          Hotsndot

                          212




                          212






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448177%2fcompare-two-variables-with-a-shell-script%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?