Space separated argument to script











up vote
0
down vote

favorite












I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.



foo-wrapper.sh content:



#/!bin/bash
foo $1


When running foo-wrapper.sh:



$bash -x foo-wrapper.sh "'A B'"
+ Error: foo ''''A' 'B''''


The expected call would be: foo 'A B'



Any ideas how to make that work?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.



    foo-wrapper.sh content:



    #/!bin/bash
    foo $1


    When running foo-wrapper.sh:



    $bash -x foo-wrapper.sh "'A B'"
    + Error: foo ''''A' 'B''''


    The expected call would be: foo 'A B'



    Any ideas how to make that work?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.



      foo-wrapper.sh content:



      #/!bin/bash
      foo $1


      When running foo-wrapper.sh:



      $bash -x foo-wrapper.sh "'A B'"
      + Error: foo ''''A' 'B''''


      The expected call would be: foo 'A B'



      Any ideas how to make that work?










      share|improve this question















      I'm trying to use a wrapper bash script to execute some command with one parameter separated by space 'A B'.



      foo-wrapper.sh content:



      #/!bin/bash
      foo $1


      When running foo-wrapper.sh:



      $bash -x foo-wrapper.sh "'A B'"
      + Error: foo ''''A' 'B''''


      The expected call would be: foo 'A B'



      Any ideas how to make that work?







      bash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      Micha Wiedenmann

      9,6891164102




      9,6891164102










      asked 2 days ago









      ntrax111

      406




      406
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted











          • In the wrapper replace $1 by "$1".

            If your arguments/variables contain space characters, you need to quote them to prevent them from being split.


          • In the call instead of "'A B'" use one of "A B", 'A B' or A B.

            These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)



          If you want to play around a little to get a feeling, you can start with:



          $ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
          $ foo A B C
          count: 2
          arg 1: A B
          arg 2: C





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372828%2fspace-separated-argument-to-script%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








            up vote
            1
            down vote



            accepted











            • In the wrapper replace $1 by "$1".

              If your arguments/variables contain space characters, you need to quote them to prevent them from being split.


            • In the call instead of "'A B'" use one of "A B", 'A B' or A B.

              These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)



            If you want to play around a little to get a feeling, you can start with:



            $ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
            $ foo A B C
            count: 2
            arg 1: A B
            arg 2: C





            share|improve this answer



























              up vote
              1
              down vote



              accepted











              • In the wrapper replace $1 by "$1".

                If your arguments/variables contain space characters, you need to quote them to prevent them from being split.


              • In the call instead of "'A B'" use one of "A B", 'A B' or A B.

                These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)



              If you want to play around a little to get a feeling, you can start with:



              $ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
              $ foo A B C
              count: 2
              arg 1: A B
              arg 2: C





              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted







                • In the wrapper replace $1 by "$1".

                  If your arguments/variables contain space characters, you need to quote them to prevent them from being split.


                • In the call instead of "'A B'" use one of "A B", 'A B' or A B.

                  These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)



                If you want to play around a little to get a feeling, you can start with:



                $ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
                $ foo A B C
                count: 2
                arg 1: A B
                arg 2: C





                share|improve this answer















                • In the wrapper replace $1 by "$1".

                  If your arguments/variables contain space characters, you need to quote them to prevent them from being split.


                • In the call instead of "'A B'" use one of "A B", 'A B' or A B.

                  These are the most usual ways of specifying strings in BASH. (Note that the whitespace only makes a difference in the 3rd case. You would have to use quotes in the first two cases no matter whether you have a space or not.)



                If you want to play around a little to get a feeling, you can start with:



                $ foo() { echo "count: $#"; echo "arg 1: $1"; echo "arg 2: $2"; }
                $ foo A B C
                count: 2
                arg 1: A B
                arg 2: C






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 days ago

























                answered 2 days ago









                Micha Wiedenmann

                9,6891164102




                9,6891164102






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372828%2fspace-separated-argument-to-script%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

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]